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. wininet API调用,检测网络

    [DllImport("wininet")]        private extern static bool InternetGetConnectedState(out int ...

  2. MySQL 行子查询

    MySQL 行子查询 行子查询是指子查询返回的结果集是一行 N 列,该子查询的结果通常是对表的某行数据进行查询而返回的结果集. 一个行子查询的例子如下: SELECT * FROM table1 WH ...

  3. php视图操作

    一.视图的基本介绍          视图是虚拟的表.与包含数据的表不一样,视图只包含使用时动态检索数据的查询.         使用视图需要MySQL5及以后的版本支持.         下面是视图 ...

  4. uva10020 贪心

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. 你好,C++(26)如何与函数内部进行数据交换?5.1.3 函数参数的传递

    5.1.3  函数参数的传递 我们知道,函数是用来完成某个功能的相对独立的一段代码.函数在完成这个功能的时候,往往需要外部数据的支持,这时就需要在调用这个函数时向它传递所需要的数据它才能完成这个功能获 ...

  6. svn用法

    SVN安装与启动服务 1.下载相应匹配版本的TortoiseSVN(客户端)和Subversion(客户端),安装完毕之后. 2.配置相关文件. 选择TortoiseSVN-->create r ...

  7. iOS 3D Touch功能 3 -备

    新的触摸体验——iOS9的3D Touch 一.引言 二.在模拟器上学习和测试3D Touch 附.SBShortcutMenuSimulator的安装和使用 三.3D Touch的主要应用 四.3D ...

  8. iOS开发之UIWebView自动滑动到顶部-备

    但可以通过subview来操作. 通常用UIWebView加载网页,有时候需要点击一个按钮,或者页面的某个部位,使页面自动滚动到顶部,但是UIWebView不像UIScrollView那么方便.   ...

  9. Cracking the coding interview--Q1.4

    原文 Write a method to replace all spaces in a string with'%20'. You may assume that the string has su ...

  10. 读UNDO引发的db file sequential read

    SQL> select * from (select SESSION_ID, NAME, P1, P2, P3, WAIT_TIME, CURRENT_OBJ#, CURRENT_FILE#, ...