POJ 3692:Kindergarten 求补图的最大点独立集 头一次接触这样的做法
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5884 | Accepted: 2877 |
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 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
题意是幼儿园有很多小孩,男生和男生互相熟悉,女生和女生互相熟悉。然后给出了一些男生和一些女生互相熟悉的关系,要找到一个最大的群体,这个群体中所有人都互相熟悉,问这个群体最多多少人。
二分图的最大点独立集(二分图中两两互不相连的点的集合) = N - 二分图的最大匹配数量
这个题要求的点独立集是要两两互相连,所以这要求的是补图的最大点独立集。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int grid[205][205];
int link[205];
int visit[205];
int n,m,k,V1,V2;
int result; bool dfs(int x)
{
int i;
for(i=1;i<=V2;i++)
{
if(grid[x][i]==0&&visit[i]==0)
{
visit[i]=1;
if(link[i]==-1||dfs(link[i]))
{
link[i]=x;
return true;
}
}
}
return false;
} void Magyarors()
{
int i; result=0;
memset(link,-1,sizeof(link));//!!这里不能是0 for(i=1;i<=V1;i++)
{
memset(visit,0,sizeof(visit));
if(dfs(i))
result++;
}
cout<<V1+V2-result<<endl;
} int main()
{
int i,j,pair,temp1,temp2; for(i=1;;i++)
{
scanf("%d%d%d",&n,&m,&pair);
V1=n;
V2=m;
if(n==0&&m==0&&pair==0)
break; cout<<"Case "<<i<<": ";
memset(grid,0,sizeof(grid)); for(j=1;j<=pair;j++)
{
scanf("%d%d",&temp1,&temp2);
grid[temp1][temp2]=1;
}
Magyarors();
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 3692:Kindergarten 求补图的最大点独立集 头一次接触这样的做法的更多相关文章
- POJ 3692 Kindergarten(最大团问题)
题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...
- POJ 3692 Kindergarten (补图是二分图的最大团问题)
题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...
- 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 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...
- poj 3692 Kindergarten (最大独立集)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4903 Accepted: 2387 Desc ...
- poj 3692 Kindergarten (最大独立集之逆匹配)
Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...
- poj 3692 Kindergarten
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6956 Accepted: 3436 Desc ...
- BZOJ1143:祭祀river(二分图求有向图的最大点独立集)
在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都 会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河道连接着 ...
- POJ 3692 Kindergarten(二分图最大独立集)
题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...
随机推荐
- 时间和日期-<Date和SimpleDateFormat>
第一步.定义一个Date //获取当前时间 Date now=new Date(); 第二步.定义一个SimpleDateFormat //规范时间格式 SimpleDateFormat date=n ...
- UCOS-III API函数
附录:UCOS-III API函数 任务管理 就绪列表 挂起队列 时间管理 信号量 消息队列 内存管理
- Linux centos7 LAMP架构介绍、 MySQL、MariaDB介绍、MySQL安装
一.LAMP架构介绍 为Linux+Apache(httpd)+MySQL+PHP简写,把后三者安装在Linux Apache是最常用的的web服务软件,MySQL为小型的数据库存储软件,PHP为脚本 ...
- .Net使用SharpZip解压缩文件
最近,项目中使用到了上传压缩文件,文件上传到服务器后,肯定要解压,取出其中的文件才能使用,在这里做一个小结,Get这个新技能. 首先在使用NuGet管理程序在项目中添加引用ICSharpCode.Sh ...
- 中山普及Day17——普及
今天换教室,本来教室多好嘛,易守难攻,结果...今天今天仅下午就被熊抄了2次,熊超真TMD不是人呐,走路连脚步声都没有. 然后,播报分数: 爆0了!!!
- keep-alive的使用
<keep-alive>是Vue的内置组件,能在组件切换过程中将状态保留在内存中,防止重复渲染DOM. <router-view>中间为组件</router-view&g ...
- swift正点
Openstack Swift 原理.架构与 API 介绍 http://www.openstack.cn/?p=776 ——Openstack Swift 开源云存储技术解析 OpenStack S ...
- 微信小程序(基础)
文档官网:https://developers.weixin.qq.com/miniprogram https://developers.weixin.qq.com/miniprogram/dev/f ...
- Android中的Sqlite中的onCreate方法和onUpgrade方法的执行时机--(转)
原文:http://blog.csdn.net/jiangwei0910410003/article/details/46536329 今天在做数据库升级的时候,遇到一个问题,就是onCreate方法 ...
- Linux centosVMware zip压缩工具、tar打包、打包并压缩
一. zip压缩工具 可以用来压缩文件和目录,压缩目录是需要指定目录下的文件. [root@davery tmp]# cp 1.txt davery/[root@davery tmp]# du -sh ...