HDU2458 最大团个数=顶点数-补图的最大匹配数(补图的最大独立集)

Kindergarten

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1386    Accepted Submission(s): 736


Problem Description
In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all players know each other. You are to help to find maximum number of kids the teacher can pick.
 

Input
The input consists of multiple test cases. Each test case starts with a line containing three integers
G, B (1 ≤ G, B ≤ 200) and M (0 ≤ M ≤ G × B), which is the number of girls, the number of boys and
the number of pairs of girl and boy who know each other, respectively.
Each of the following M lines contains two integers X and Y (1 ≤ X≤ G,1 ≤ Y ≤ B), which indicates that girl X and boy Y know each other.
The girls are numbered from 1 to G and the boys are numbered from 1 to B.

The last test case is followed by a line containing three zeros.
 

Output
For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the maximum number of kids the teacher can pick.
 

Sample Input
 
  
2 3 31 11 22 32 3 51 11 22 12 22 30 0 0
 
Sample Output
 
  
Case 1: 3Case 2: 4
 

题意概括:

   G个女生,B个男生,M组关系,性别相同的同学默认互相认识,现在需要找出一个的组,组内的所有人必须互相认识,问这个组最多能有多少人?

代码:

#include<stdio.h>
#include<string.h>
#define N 220
int map[N][N],u,v,book[N];
int boy[N];
int g,b,m;
int find(int x)
{
	int i,j;
	for(i=1;i<=b;i++)
	{
		if(book[i]==0&&map[x][i]==0)
		{
			book[i]=1;
			if(boy[i]==0||find(boy[i])==1)
			{
				boy[i]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	int i,j,k,d,t;
	t=0;
	while(scanf("%d%d%d",&g,&b,&m)!=EOF)
	{
		if(g+b+m==0)
			break;
		t++;
		memset(map,0,sizeof(map));

		for(i=0;i<m;i++)
		{
			scanf("%d%d",&u,&v);
			map[u][v]=1;//这里把认识的置为1,匹配的时候用0,代表补图
		}
		
		memset(boy,0,sizeof(boy));
		d=0;
		for(i=1;i<=g;i++)
		{
			memset(book,0,sizeof(book));
			if(find(i)==1)
			{
				d++;
			}
		}
	//	printf("%d\n",d);
		printf("Case %d: %d\n",t,g+b-d);
	}
	return 0;
}


 

猜你喜欢

转载自blog.csdn.net/Gakki_wpt/article/details/80379974