HDU 2458 Kindergarten

来源:互联网 发布:最大的网络直播平台 编辑:程序博客网 时间:2024/04/30 07:54

Kindergarten

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


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
 

Source

2008 Asia Hefei Regional Contest Online by USTC

解题思路:求最大团,等价于求补图的最大独立集

#include<stdio.h>#include<string.h>#define MAXN 1000000+100struct aa{   int a,b,next;}D[MAXN];int list[MAXN],tot;int mkdfs[210];int mkgx[210];int mkmp[210][210];void add(int a,int b){   D[++tot].a=a;   D[tot].b=b;   D[tot].next=list[a];   list[a]=tot;}int dfs(int a){  for(int k=list[a];k;k=D[k].next)  {     int to=D[k].b;     if(mkdfs[to])  continue;     mkdfs[to]=1;     if(mkgx[to]==-1||dfs(mkgx[to]))     {        mkgx[to]=a;        return 1;      }    }    return 0;}int main (){  int G,B,n,i,j,k,t=1,a,b,ans;  while(~scanf("%d%d%d",&G,&B,&k)&&G+B+k)  {      for(i=1;i<=200;i++)          for(j=1;j<=200;j++)              mkmp[i][j]=1;         for(i=1;i<=k;i++)      {         scanf("%d%d",&a,&b);         mkmp[a][b]=0;      }      memset(list,0,sizeof(list));      tot=0;      for(i=1;i<=G;i++)          for(j=1;j<=B;j++)          {             if(mkmp[i][j])                 add(i,j);          }       memset(mkgx,255,sizeof(mkgx));       ans=0;       for(i=1;i<=G;i++)       {          memset(mkdfs,0,sizeof(mkgx));          ans+=dfs(i);       }       printf("Case %d: %d\n",t++,G+B-ans);     }     return 0;}


0 0
原创粉丝点击