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;
    }


  • 相关阅读:
    腾讯X5内核使用详解(X5内核播放器使用如何去除控制栏全屏播放)以及一些注意事项
    易语言加壳SDK(宏标记)
    安卓相对布局常用语句
    安卓平分位置layout_weight学习记录
    为什么要前后端分离?各有什么优缺点?
    前端开发技术路线
    超实用的JQuery小技巧
    HTML元素脱离文档流的三种方法
    Promise的理解
    JS闭包是什么?
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273457.html
Copyright © 2011-2022 走看看