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 ...
随机推荐
- linux下解压压缩rar文件
http://download.csdn.net/detail/hnust_xiehonghao/6679893 下载地址 1. 下载软件 以rarlinux-3.8.0 for linux为例, ...
- [React Testing] Element types with Shallow Rendering
When you render a component with the Shallow Renderer, you have access to the underlying object. We ...
- js中substring和substr的用法 (转)
1.substring 方法 定义和用法 substring 方法用于提取字符串中介于两个指定下标之间的字符. 语法 stringObject.substring(start,stop) 参数 ...
- Servlet 技术全总结 (已完成,不定期增加内容)
Servlet是独立于平台和协议的服务器端的java应用程序,处理请求的信息并将其发送到客户端. Servlet的客户端可以提出请求并动态获得响应. Servlet动态生成web页面,担当浏览器或其他 ...
- dom的element类型
1)getElementById 后面的nodeName和tagName都一样 var a=document.getElementById("my_div"); console.l ...
- js 获取mac地址
js 获取mac地址 function MacInfo(){ var locator =new ActiveXObject ("WbemScripting.SWbemLocator" ...
- jQuery 2.2 和 1.12 新版本发布
新年新气象,jQuery 团队于昨日发布了两个新版本:1.12 和 2.2.这两个版本都包含了大量的Bug修正和功能改进.基本上这会是3.0之前最后一次发布.不过由于3.0不做向下兼容,所以届时 jQ ...
- jQuery ajax传递特殊字符串问题
当你用ajax传递值到服务器端,如果值中包含特殊字符串如+,&等,在服务器端获取的结果可能就会出现差异,因为这些字符有其它用途,如“+”表示连接符,在转义后你获取到的就是空格.可以看看这些特殊 ...
- C语言写猜拳游戏中遇到的函数循环小问题
各位可能在初学C语言的时候都有写过猜拳游戏.但在写猜拳的函数时,避免不了会使用循环. 当函数被套在一个循环中的时候,你的计分变量可能就会被重置为函数体里的初始值.那么怎么解决这个问题? 其实很简单,你 ...
- AngularJS自定义表单控件
<!doctype html> <html ng-app="myApp"> <head> <script src="G:\\So ...