3692 Kindergarten //MaxMatch 二分图求最大团

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 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 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<stdio.h>
#include<string.h>
int 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;
}

你可能感兴趣的:(Integer,BI,input,each)