POJ3692 Kindergarten 【最大独立集】
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5317 | Accepted: 2589 |
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
Source
题意:在幼儿园中。全部男孩间都相互认识,女孩彼此也都认识。有一些男孩跟一些女孩认识,如今给定这些认识关系,选定一个最大的点集使得里面每一个人都相互认识。
题解:二分图的独立集仅仅从二分图G = (X,Y;E)选取一些点v属于{X, Y}。使得点集v中随意两点间没有通过边链接。而二分图的最大独立集模型就是求取max|v|。
有例如以下公式:
最大独立集顶点个数 = 节点数(|X|+|Y|)- 最大匹配数。
#include <stdio.h>
#include <string.h> #define maxn 205 bool G[maxn][maxn], visy[maxn];
int girl[maxn], boy[maxn];
int g, b, m, cas = 1; void getMap() {
int u, v;
memset(G, 0, sizeof(G));
while(m--) {
scanf("%d%d", &u, &v);
G[u][v] = true;
}
} int findPath(int x) {
int i;
for(i = 1; i <= b; ++i) {
if(!G[x][i] && !visy[i]) {
visy[i] = 1;
if(boy[i] == -1 || findPath(boy[i])) {
boy[i] = x; return 1;
}
}
}
return 0;
} int MaxMatch() {
int i, ans = 0;
memset(girl, -1, sizeof(girl));
memset(boy, -1, sizeof(boy));
for(i = 1; i <= g; ++i) {
memset(visy, 0, sizeof(visy));
ans += findPath(i);
}
return ans;
} void solve() {
printf("Case %d: %d\n", cas++, g + b - MaxMatch());
} int main() {
while(scanf("%d%d%d", &g, &b, &m), g | b | m) {
getMap();
solve();
}
return 0;
}
POJ3692 Kindergarten 【最大独立集】的更多相关文章
- poj 3692 Kindergarten (最大独立集)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4903 Accepted: 2387 Desc ...
- POJ3692 Kindergarten
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6882 Accepted: 3402 Desc ...
- POJ3692 Kindergarten —— 二分图最大团
题目链接:http://poj.org/problem?id=3692 Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Sub ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
- 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(最大独立集)
[题目链接] http://poj.org/problem?id=3692 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...
- POJ 3692 Kindergarten(二分图最大独立集)
题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...
- poj3692 最大点权独立集/最大独立集
题意:有男孩和女孩,男孩之间全部认识,女孩之间全部认识,一部分男孩和女孩认识,现在希望选出一些孩子,这些孩子都相互认识. 方法:正的做不好做,观察他的补图,补图之间无关系的边就是原图有关系的.补图中的 ...
- POJ 3692 Kindergarten (二分图 最大团)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5660 Accepted: 2756 Desc ...
随机推荐
- ASP.Net MVC 之FileResult
FileResult是一个基于文件的ActionResult,利用FileResult我们可以很容易地将从某个物理文件的内容响应给客户端.ASP.NET MVC定义了三个具体的FileResult,分 ...
- (转)CentOS下用yum搭建LNMP服务器
原文链接:http://www.xiaohuai.com/2733 CentOS下搭服务器也折腾好几次了, 每次都知道个大概, 具体repo的地址什么的还都要现找, 实在不效率, 干脆整理记录下来. ...
- DirectX Graphics Infrastructure (DXGI) 全屏设置相关问题
原文地址: https://msdn.microsoft.com/en-us/library/windows/desktop/ee417025(v=vs.85).aspx 未完待续... DXGI是在 ...
- 武汉科技大学ACM:1005: 华科版C语言程序设计教程(第二版)例题5.8
Problem Description 老师给小豪出了一道题目:给你两个整数x和n(-10<=x<=10,1<=n<=10),让你求出x^1+x^2+x^3+……+x^n的结果 ...
- Linux中的搜索命令
find find是最常见和最强大的查找命令,在磁盘中查找文件,用它找到任何你想找的文件,就是速度有点慢. find path -option [ -print ] [ ...
- [转]javascript函数定义表达式和函数声明的区别
在javascript中,函数有两种定义写法,函数定义表达式和函数声明,其例子分别如下所示: var test = function(x){ return x; } function test(x){ ...
- CSS中zoom:1的作用
兼容IE6.IE7.IE8浏览器,经常会遇到一些问题,可以使用zoom:1来解决,有如下作用:触发IE浏览器的haslayout解决ie下的浮动,margin重叠等一些问题.比如,本站使用DIV做一行 ...
- jquery判断滚动条到底
$(document).scroll(function(){ var dHeight = $(document).height(); var wHeight = $(window).height(); ...
- Nginx源码研究三:Epoll在NGINX中的使用
Web服务器在面对高并发的情况下,网络的IO一般选择IO复用,像apache选择的Select/poll.Nginx在linux 2.6后选择Epoll做网路IO,提高了WEB服务的并发能力. 在本章 ...
- Swift—使用try?和try!区别-备
在使用try进行错误处理的时候,经常会看到try后面跟有问号(?)或感叹号(!),他们有什么区别呢? 1.使用try? try?会将错误转换为可选值,当调用try?+函数或方法语句时候,如果函数或方 ...