POJ3692:Kindergarten(最大团)
来源:互联网 发布:三菱plc3u编程手册 编辑:程序博客网 时间:2024/03/29 12:39
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 <iostream># include <cstdio># include <cstring>using namespace std;int n, m, g[203][203], l[203], vis[203];int dfs(int u){ for(int i=1; i<=m; ++i) { if(!g[u][i] && !vis[i]) { vis[i] = 1; if(l[i] == -1 || dfs(l[i])) { l[i] = u; return 1; } } } return 0;}int main(){ int k, cas=1; while(~scanf("%d%d%d",&n,&m,&k),n+m+k) { memset(g, 0, sizeof(g)); memset(l, -1, sizeof(l)); while(k--) { int x, y; scanf("%d%d",&x,&y); g[x][y] = 1; } int ans = 0; for(int i=1; i<=n; ++i) { memset(vis, 0, sizeof(vis)); if(dfs(i)) ++ans; } printf("Case %d: %d\n",cas++,n+m-ans); } return 0;}
- POJ3692:Kindergarten(最大团)
- 二分图最大团-poj3692
- poj3692二分图最大团
- POJ 3692:Kindergarten(最大团)
- poj 3692 -- Kindergarten(最大团,匈牙利)
- Poj 3692 Kindergarten【最大团】
- poj3692----图论---二分图最大团
- poj3692 二分图的最大团
- poj3692 补图二分图,最大团
- POJ3692:Kindergarten
- POJ3692 Kindergarten
- poj3692 Kindergarten
- poj 3692 Kindergarten (最大团模板题)
- HDU 2458Kindergarten(二分图 最大团点数)
- POJ 3692 Kindergarten(二分图最大团)
- POJ 3692 Kindergarten(二分图最大团)
- POJ 3692 Kindergarten (二分图 最大团)
- HDU 2458 — Kindergarten 最大团
- JSP 中EL表达式用法详解
- 机器学习
- centos搭建LNMP环境
- netty实现websocket
- Struts2项目实战 微云盘 效果展示
- POJ3692:Kindergarten(最大团)
- Java多线程(上篇)
- 函数式编程(2) 高阶函数(转自: 周见智)
- 机器学习
- PHP POSIX扩展正则表达式函数
- logistic regression 处理鸢尾花数据集
- Struts2整合Spring的两种方式(最新)
- 看我是怎么学SLAM(一)——Kinect+Kobuki开发环境总和篇
- Mac Sublime Text3 快捷键