hdu2458 2010.3.6
二分图,建图的方式很特别,会想不到——没有关系的建一条边
Kindergarten
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 111 Accepted Submission(s): 58
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. Inaddition to that, some girls and boys know each other. Now the teachers want topick some kids to play a game, which need that all players know each other. Youare 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 whoknow each other, respectively.
Each of the following M lines contains twointegers 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 theboys are numbered from 1 to B.
The last test case is followed by a linecontaining three zeros.
Output
For each test case, print a line containingthe test case number( beginning with 1) followed by a integer which is themaximum number of kids the teacher can pick.
Sample Input
2 3 3
1 1
1 2
2 3
2 3 5
1 1
1 2
2 1
2 2
2 3
0 0 0
Sample Output
Case 1: 3
Case 2: 4
Source
2008 Asia Hefei Regional Contest Online by USTC
Recommend
teddy
#include <stdio.h>
#include <string.h>
#define MAX 210
char map[MAX][MAX],yt[MAX];
int g,b,y[MAX];
int judge(int);
int main(void)
{
int m,i,p,q,t,sum;
t=0;
scanf("%d %d %d",&g,&b,&m);
while (g!=0 || b!=0 || m!=0)
{
t++;
memset(map,0,sizeof(map));
while (m>0)
{
scanf("%d %d",&p,&q);
map[p][q]=1;
m--;
}
sum=0;
memset(y,0,sizeof(y));
for (i=1;i<=g;i++)
{
memset(yt,0,sizeof(yt));
if (judge(i)) sum++;
}
printf("Case %d: %d\n",t,g+b-sum);
scanf("%d %d %d",&g,&b,&m);
}
return 0;
}
int judge(int a)
{
int i;
for (i=1;i<=b;i++)
{
if (!map[a][i] && !yt[i])
{
yt[i]=1;
if (y[i]==0 || judge(y[i]))
{
y[i]=a;
return 1;
}
}
}
return 0;
}