3692 Kindergarten//MaxMatch 이분도구 최대단

2680 단어 IntegerBIinputeach
Kindergarten
Time Limit: 2000MS
 
Memory Limit: 65536K
Total Submissions: 2430
 
Accepted: 1069
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 integersG, B (1 ≤ G, B ≤ 200) and M (0 ≤ M ≤ G × B), which is the number of girls, the number of boys andthe 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 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
 
 
독립 집합: 임의의 두 점도 연결되지 않는 정점의 집합 독립 수: 독립 집합 정점의 개
전체 하위 그림: 임의의 두 점이 연결된 정점의 집합 최대 전체 수: 최대 전체 하위 그림의 정점 개수
최대 완전수 = 원본 그래프의 최대 독립수 최대 독립수 = 정점수 - 최대 일치수 = 원본 그래프의 최대 단수
 
 
#include#includeint g,b,n;bool mat[201][201];int link[201];bool usedif[201];bool can(int t){    for(int i=1;i<=b;i++)    if(usedif[i]==false&&mat[t][i]==1)    {        usedif[i]=true;        if(link[i]==-1||can(link[i]))        {            link[i]=t;            return true;        }    }    return false;}int MaxMatch(){    int num=0;    memset(link,-1,sizeof(link));    for(int i=1;i<=g;i++)    {        memset(usedif,false,sizeof(usedif));        if(can(i))   num++;    }    return num;}int main(){    int cas=1;    while(scanf("%d%d%d",&g,&b,&n)!=EOF)    {        if(g==0&&b==0&&n==0)  break;        memset(mat,true,sizeof(mat));        for(int i=1;i<=n;i++)        {            int x,y;            scanf("%d%d",&x,&y);            mat[x][y]=false;        }        printf("Case %d: %d/n",cas++,g+b-MaxMatch());    }    return 0;}

좋은 웹페이지 즐겨찾기