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

GB (1 ≤ GB ≤ 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 【最大独立集】的更多相关文章

  1. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  2. POJ3692 Kindergarten

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6882   Accepted: 3402 Desc ...

  3. POJ3692 Kindergarten —— 二分图最大团

    题目链接:http://poj.org/problem?id=3692 Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Sub ...

  4. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

  5. poj 3692 Kindergarten (最大独立集之逆匹配)

    Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...

  6. POJ 3692 Kindergarten(最大独立集)

    [题目链接] http://poj.org/problem?id=3692 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...

  7. POJ 3692 Kindergarten(二分图最大独立集)

    题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...

  8. poj3692 最大点权独立集/最大独立集

    题意:有男孩和女孩,男孩之间全部认识,女孩之间全部认识,一部分男孩和女孩认识,现在希望选出一些孩子,这些孩子都相互认识. 方法:正的做不好做,观察他的补图,补图之间无关系的边就是原图有关系的.补图中的 ...

  9. POJ 3692 Kindergarten (二分图 最大团)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 Desc ...

随机推荐

  1. SqlServer数据库设计,纠结的问题,有胆你就来!

    最近,小菜遇到了数据库设计上的一个问题,希望各位大侠再次,直抒己见,帮忙分析一下.也可有更好的设计,请直接提出来. 要求:数据库(SQL Server 2005)存储每个学生,单个客观题答案.分数,主 ...

  2. 设置Cacti图形标题能显示中文

    1.查看系统是否带有中文字体包 # ls /usr/share/fonts/chinese 如没有则安装 # yum -y install fonts-chinese   2.设置cacti使用的rr ...

  3. C# linq的学习及使用

    linq可以对多种数据源和对象进行查询,如数据库.数据集.XML文档.数组等. 通过对linq的使用,可以减少代码量并优化检索操作. LINQ关键字 from 指定数据源和范围变量 where 根据布 ...

  4. Html jquery实现根据 IOS和Android访问跳转

    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script> ...

  5. WDCP一些常用的一健安装包可选安装组件

    为有更好的性能,也为更简洁的系统,一些不是常用或不是基本的功能,都将做为可选的安装组件需要用到的就安装 memcache的安装 wget -c http://down.wdlinux.cn/in/me ...

  6. PHP安全设置(转载)

    大家都知道PHP已经是当前最流行的Web应用编程语言了.但是也与其他脚本语言一样,PHP也有几个很危险的安全漏洞.所以在这篇教学文章中,我们将大致看看几个实用的技巧来让你避免一些常见的PHP安全问题. ...

  7. 6 个轻量级并且灵活的 PHP CMS 系统

    Anchor CMS Just like its introduction says, Anchor has a very simple UI. The installation takes lite ...

  8. iOS开发——C篇&结构体与枚举

    一:结构体与枚举的介绍: 结构体与枚举:是一种存储复杂的数据结构体:是用户自定义的一种类型,不同类型的集合,而数组是相同类型变量的集合. 二:结构体的创建 struct user {     char ...

  9. Facebook和Google如何激发工程师的创造力

    http://taiwen.lofter.com/post/664ff_ad8a15 今天终于“朝圣”了两个伟大的公司——Facebook和Google,对创造力和驱动力的来源有了更多的理解,尤其是对 ...

  10. 转:解决方案your project contains error s please fix them before running your application

    文章来自于:http://www.mythroad.net/2013/08/05/%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88your-project-contains-e ...