zoukankan      html  css  js  c++  java
  • poj--3692--Kindergarten(最大独立集)

    Kindergarten
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 6059   Accepted: 2982

    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
    GB (1 ≤ GB ≤ 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

    求补图的最大独立集,最大独立集=节点数-最大匹配数

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    #define MAXN 1010
    int pipei[MAXN],used[MAXN],map[MAXN][MAXN];
    int G,B,M;
    int find(int u)
    {
    	for(int i=1;i<=B;i++)
    	{
    		if(!used[i]&&map[u][i]==0)
    		{
    			used[i]=1;
    			if(pipei[i]==-1||find(pipei[i]))
    			{
    				pipei[i]=u;
    				return 1;
    			}
    		}
    	}
    	return 0;
    }
    int main()
    {
    	int Case=1;
    	while(scanf("%d%d%d",&G,&B,&M)!=EOF)
    	{
    		if(B==0&&G==0&&M==0)
    		break;
    		memset(pipei,-1,sizeof(pipei));
    		memset(map,0,sizeof(map));
    		int a,b;
    		for(int i=0;i<M;i++)
    		{
    			scanf("%d%d",&a,&b);
    			map[a][b]=1;
    		}
    		int ans=0;
    		for(int i=1;i<=G;i++)
    		{
    			memset(used,0,sizeof(used));
    			ans+=find(i);
    		}
    		printf("Case %d: %d
    ",Case++,B+G-ans);
    	}
    	return 0;
    }


  • 相关阅读:
    Java+TestNG+Maven+Excel+IDEA接口自动化入门(二)Get方法
    java8新特性lambda和Stream新手springboot案例2020年新版
    h2数据库作为内存型与springboot+mybatis的案例
    分布式远程调用SpringCloud-Feign的两种具体操作方式(精华)
    携程Apollo简单入门教程这一篇就够了
    【Linux系列一】安装JDK
    【SVN系列一】更新失败
    Centos7配置桥接网络
    Vm虚拟机最小化安装linux并配置NAT网络连接(全图)
    python 函数传递
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273457.html
Copyright © 2011-2022 走看看