Kindergarten
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 4787   Accepted: 2326

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 ≤ MG × 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

Source

 
二分图找最大独立集
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; #define maxn 500 int g,b,m,ans;
bool f[maxn][maxn],vis[maxn];
int match[maxn]; bool dfs(int u) {
for(int i = g + ; i <= g + b; ++i) {
if(vis[i] || f[u][i] || u == i) continue;
vis[i] = ;
if(match[i] == - || dfs(match[i])) {
match[i] = u;
return true;
}
} return false;
}
void solve() {
for(int i = ; i <= g + b; ++i) match[i] = -; for(int i = ; i <= g; ++i) {
memset(vis,,sizeof(vis));
if(dfs(i)) ++ans;
}
}
int main()
{
// freopen("sw.in","r",stdin); int ca = ; while(~scanf("%d%d%d",&g,&b,&m)) {
memset(f,,sizeof(f));
if(!g && !b && !m) break;
ans = ; for(int i = ; i <= m; ++i) {
int x,y;
scanf("%d%d",&x,&y);
f[x][y + g] = ;
} solve(); // printf("ans = %d\n",ans); printf("Case %d: %d\n",++ca,g + b - ans); } return ;
}

POJ 3692的更多相关文章

  1. POJ 3692 Kindergarten (二分图 最大团)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 Desc ...

  2. POJ 3692 Kindergarten(最大团问题)

    题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...

  3. POJ 3692 Kindergarten(最大独立集)

    [题目链接] http://poj.org/problem?id=3692 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...

  4. POJ 3692:Kindergarten(最大的使命)

    id=3692">Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4920   Ac ...

  5. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  6. POJ 3692 Kindergarten (补图是二分图的最大团问题)

    题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...

  7. poj 3692 二分图最大匹配

    思路: 如果我们将认识的建边,求最大独立集就是互相不认识的人数.那么我们反过来,将不认识的建图,求最大独立集就是互相认识的人数. #include<cstdio> #include< ...

  8. POJ 3692 最大独立集

    题意:有G个女生,B个男生,所有的女生都互相认识,所有的男生都互相认识,还有N对男女,他们互相认识. 问从中选出最多的人数,是的他们全部互相认识. 思路:这道题的构图很巧妙,对于他的补图构图,对于所有 ...

  9. poj 3692 Kindergarten (最大独立集之逆匹配)

    Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...

随机推荐

  1. UITextField使用的相关方法

    1.设置占位符 textField.placeholder = @“”; 2.设置暗文输入 textField.secureTextEntry = YES;   3.设置键盘类型 textField. ...

  2. 如何从官网下载springframework和document

    spring官网 http://spring.io/ --->spring project--->点击github图标 --->artifactory --->进入到了http ...

  3. 读TCP-IP详解卷1:协议(1)

    1.TCP传给IP的数据单元称作TCP报文段或简称为TCP段(TCP segment)IP传给网络接口层的数据单元称作IP数据报(IPdatagram).通过以太网传输的比特流称作帧(Frame).

  4. P1689: [Usaco2005 Open] Muddy roads 泥泞的路

    水题,模拟就行了,别忘了L>=r的时候直接更新下一个的L然后continue type node=record l,r:longint; end; var n,l,i,ans:longint; ...

  5. vsftpd配置文件说明

    (1)常用选项: chroot_local_user=YES #限制所有的用户均不能切换到其他目录 allow_writeable_chroot=YES #允许根目录可写 FTP的工作模式有两种,一种 ...

  6. 通过 CALayer 修改 UIImageView 的界面属性

    界面属性的修改是每一个开发者必须知道的,为什么我就记不住呢, shit, 又耽误了时间,为了防止再找不到,特把一些常用的 CALayer属性记在这里,顺便分享 1.设置阴影 1 imageView.l ...

  7. React + Reflux

    React + Reflux 渲染性能优化原理   作者:ManfredHu 链接:http://www.manfredhu.com/2016/11/08/23-reactRenderingPrinc ...

  8. USB硬件远程共享解决iphone已停用

    悲剧的在iphone拆过电池之后,再开机显示iphone已停用,请在23000000分钟后再试一次 算算这得45年了,可以留给孙子用了... 网上除了刷机和有同步过的电脑貌似没有别的办法了 因是旧系统 ...

  9. Differences Between Xcode Project Templates for iOS Apps

    Differences Between Xcode Project Templates for iOS Apps When you create a new iOS app project in Xc ...

  10. Team Homework #3 软件工程在北航——IloveSE

    任务要求: 采访以前上过北航  (计算机系/软件学院) 软件工程课的同学.现在上研/工作的也可以. 采访问题如下:* 平均每周花在这门课上的时间 (包括上课/作业/上机)    * 平均写的代码总行数 ...