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 ...
随机推荐
- C++ Win32控制台应用程序捕捉关闭事件
#include#includebool ctrlhandler( DWORD fdwctrltype ){ switch( fdwctrltype ) { // handle ...
- arcpagelistarclist列表分页
arcpagelistarclist列表分页 (DedeCMS 5.6) 名称:arcpagelist 功能:通过制定arclist的pagesize及tagid属性,配合arcpagelist标签进 ...
- 忘记mysql 5.7的密码
for windows: http://blog.chinaunix.net/uid-27570589-id-3511820.html 一.将net stop mysql; 二.在命令行中 C:\Us ...
- Android/Linux boot time优化
基于analyze_boot.py分析Android/Linux的kernel boot时间 1.修改HiKey的BoardConfig.mk文件,使能initcall_debug,增加dmesg b ...
- 网页HTML1
表格表单 表格, <tabale> -------表格 <tr> --------------行 <td> -- ...
- IE9的window.showmodaldialog显示问题
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat=&quo ...
- Oracle怎样方便地查看报警日志错误
由于报警日志文件很大,而每天都应该查看报警日志(查看有无“ORA-”,Error”,“Failed”等出错信息),故想找到一种比较便捷的方法,查看当天报警日志都有哪些错误. 在网上查了几天的资料,尝试 ...
- 东软实训4-JDBC连接数据库
JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口 ...
- 关于升级到win10后的网络问题
最近我的alienware电脑从win7升级到win10,看到很多网友都有一个问题,那就是网络受限了, 基本看了很多百度到的,方法基本都不是很有用,我看到了一个网友的办法完美解决了我机器上的网络问题, ...
- dede留言板BUG解决
dede留言板刷新后空白BUG解决 DEDE留言板验证码留空或者不正确返回空白页面的解决方法 解决方法如下进入文件/plus/guestbook.php 找到代码ShowMsg("验证码不正 ...