poj 3692 Kindergarten (最大独立集之逆匹配)
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 ( ≤ G, B ≤ ) and M ( ≤ 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 ( ≤ X≤ G, ≤ Y ≤ B), which indicates that girl X and boy Y know each other.
The girls are numbered from to G and the boys are numbered from 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 ) followed by a integer which is the maximum number of kids the teacher can pick.
Sample Input
Sample Output
Case :
Case :
Source
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 206
int G,B,M;
int mp[N][N];
int match[N];
int vis[N];
bool dfs(int x){
for(int i=;i<=B;i++){
if(!vis[i] && !mp[x][i]){//注意这里要取mp[x][i]==0!!!
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=x;
return true;
}
}
}
return false;
}
int solve(){
int ans=;
memset(match,-,sizeof(match)); for(int i=;i<=G;i++){
memset(vis,,sizeof(vis));
if(dfs(i)){
ans++;
}
}
return ans;
}
int main()
{
int ac=;
while(scanf("%d%d%d",&G,&B,&M)==){
if(G== && B== && M==)
break;
printf("Case %d: ",++ac);
memset(mp,,sizeof(mp));
for(int i=;i<M;i++){
int x,y;
scanf("%d%d",&x,&y);
mp[x][y]=;
}
int ans=solve(); printf("%d\n",G+B-ans); }
return ;
}
poj 3692 Kindergarten (最大独立集之逆匹配)的更多相关文章
- poj 3692 Kindergarten (最大独立集)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4903 Accepted: 2387 Desc ...
- POJ 3692 Kindergarten(最大独立集)
[题目链接] http://poj.org/problem?id=3692 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...
- POJ 3692 Kindergarten(二分图最大独立集)
题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...
- POJ 3692 Kindergarten (二分图 最大团)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5660 Accepted: 2756 Desc ...
- POJ 3692 Kindergarten(最大团问题)
题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...
- poj 3692 Kindergarten
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6956 Accepted: 3436 Desc ...
- POJ 3692 Kindergarten (补图是二分图的最大团问题)
题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...
- POJ 3692:Kindergarten(最大的使命)
id=3692">Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4920 Ac ...
- POJ 1466 大学谈恋爱 二分匹配变形 最大独立集
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 11694 Accepted: 5230 D ...
随机推荐
- lesson6:jmeter和badboy配合使用
由于jmeter不支持脚本的录制,只能手动设置,在某些集成型的压力测试时,使用不是很方便,这时可以和badboy一起配合使用,badboy支持网页操作的录制功能,并能把录制的操作导出为jmeter的脚 ...
- Ubuntu16.04下部署 nginx+uwsgi+django1.9.7(虚拟环境pyenv+virtualenv)
由于用的新版本系统,和旧的稍有差别,在网上搜了很多相关资料,搞了三天终于搞好在Ubuntu16.04下的部署,接下来就详细写写步骤以及其中遇到的问题.前提是安装有虚拟环境pyenv+virtualen ...
- eclipse format的时候如何让@param后不换行
- [转]Android Volley完全解析(四),带你从源码的角度理解Volley
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17656437 经过前三篇文章的学习,Volley的用法我们已经掌握的差不多了,但是 ...
- 整型数组处理算法(八)插入(+、-、空格)完成的等式:1 2 3 4 5 6 7 8 9=N[华为面试题]
有一个未完成的等式:1 2 3 4 5 6 7 8 9=N 当给出整数N的具体值后,请你在2,3,4,5,6,7,8,9这8个数字的每一个前面,或插入运算符号“+”,或插入一个运算符号“-”,或不插入 ...
- 差别client、offset、scroll系列以及event的几个距离属性
element元素结点属性 一. offset系列 1.offsetWidth 和offsetHeight element.offsetWidth是一个仅仅读属性,它包含了: css width + ...
- 高速排序-c++(分别用数组和容器实现)
/********************************************************************** *版权全部 (C)2014, cheng yang. * ...
- DC综合环境的一些概念
DC综合环境的一些概念 启动文件 .synopsys_dc_setup 采用Tcl格式,包含工艺库的路径信息和其他环境变量 不同位置启动顺序 1.Synopsys安装目录 2.用户家目录 3.项目工作 ...
- webview笔记
1. 用户上传文件 webChromeClient的onShowFileChooser这个方法,这将打开一个文件选择器,如果要取消这个请求则是调用filePathCallback.onReceiveV ...
- Linq/List/Array/IEnumerable等集合操作
来源:http://www.cnblogs.com/liushanshan/archive/2011/01/05/1926263.html 目录 1 LINQ查询结果集 1 2 Sy ...