POJ 3692
来源:互联网 发布:迈科技 知乎 编辑:程序博客网 时间:2024/06/07 03:06
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 31 11 22 32 3 51 11 22 12 22 30 0 0
Sample Output
Case 1: 3Case 2: 4
Source
#include<cstdio>#include<cstring>#define maxn 509using namespace std;int n,m;int a[maxn][maxn],cx[maxn],cy[maxn],vis[maxn];int path(int u){ int v; for(int v=1;v<=m;v++) { if(a[u][v]&&!vis[v]) { vis[v]=1; if(cy[v]==-1||path(cy[v])) { cy[v]=u; cx[u]=v; return 1; } } } return 0;}int match(){ int res=0; memset(cx,-1,sizeof(cx)); memset(cy,-1,sizeof(cy)); for(int i=1;i<=n;i++) { if(cx[i]==-1) { memset(vis,0,sizeof(vis)); res+=path(i); } } return res;}int main(){ int num,cot=0; while(scanf("%d%d%d",&n,&m,&num),n+m+num) { memset(a,0,sizeof(a));cot++; for(int i=0;i<num;i++) { int x,y; scanf("%d%d",&x,&y); a[x][y]=1; } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=a[i][j]^1; printf("Case %d: %d\n",cot,m+n-match()); }}
- poj 1466 &&poj 3692
- poj 3692
- poj 3692
- POJ 3692
- POJ 3692 最大团
- poj 3692 Kindergarten
- poj 3692 Kindergarten
- 【最大团】POJ 3692
- POJ 3692 Kindergarten
- poj 3692 Kindergarten
- poj 3692(二分匹配)
- POJ-3692-Kindergarten
- POJ 3692 Kindergarten
- POJ 3692 最大团
- POJ 3692 Kindergarten
- POJ
- poj
- POJ
- cocox2d-x CCMenuItemFon
- 如何使用VC++对ADO的扩展
- MFC单文档CEdit操作
- 活动安排问题之贪心算法
- How to Install And Configure Apache In Ubuntu
- POJ 3692
- 程序员都该阅读的书
- C语言中的位域的使用
- 二分匹配 模版 及最大总结 及 题目集合 +解析
- OS X 10.8 安装perl GD::Graph
- 大话设计模式--备忘录 Memento -- C++实现实例
- JDBC连接MySQL数据库
- Servlet监听器 Listener
- Ubuntu navicat for mysql 安装和使用