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.
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
- hdu 2458 Kindergarten 匹配
- HDU 2458 Kindergarten
- 【HDU】2458 Kindergarten 二分匹配
- hdu 2458 Kindergarten (最大独立集)
- hdu 2458 二分图匹配 Kindergarten
- HDU 2458 Kindergarten【二分图之反建边】
- HDU 2458 — Kindergarten 最大团
- HDU 2458 Kindergarten (最大独立集)
- HDU 2458Kindergarten(二分图 最大团点数)
- Kindergarten
- HDU-2458 Kindergarten 最大完全子图(最大团)中顶点的个数
- 最大匹配-HDOJ 2458 Kindergarten
- HDU 2548Kindergarten (最大独立集 + 建图细节)
- 杭电2458 Kindergarten(二分图最大匹配)
- POJ3692:Kindergarten
- poj Kindergarten
- POJ3629-Kindergarten
- POJ3692 Kindergarten
- 快速提高 Vi/Vim 使用效率的原则与途径
- Socket 功能在 Service 中实现【这才是实际的使用情况】
- iOS 系统标题翻译
- poj-2196
- Hibernate的介绍
- HDU 2458 Kindergarten
- 八步详解Hibernate的搭建及使用
- versions 出现Working copy **locked
- Hibernate总结(一)
- HDU 4822 Tri-war
- Hibernate总结(二)
- 网络管理中的常用命令
- 二分图的一些性质
- Hibernate总结(三)