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. ASP.NET数据绑定控件简介

    •数据绑定分为数据源和数据绑定控件两部分(①数据绑定控件通过数据源获取和修改数据②数据绑定控件通过数据源隔离数据提供者和数据使用者)数据绑定控件→数据源→数据库•数据源:SqlDataSource(连 ...

  2. 沙盒操作的核心函数 - NSSearchPathForDirectoriesInDomains用法

    1. iPhone会为每一个应用程序生成一个私有目录,这个目录位于: /Users/sundfsun2009/Library/Application Support/iPhone Simulator/ ...

  3. iOS 网络与多线程--4.同步Post方式的网络请求

    通过Post请求方式,同步获取网络数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据 在ViewController.m文件内的viewDidLoad函数添加一下测试代码 - (void) ...

  4. Swift2.0异常处理

    // 在抛出异常之前,我们需要在函数或方法的返回箭头 -> 前使用 throws 来标明将会抛出异常 func myMethodRetrunString() throws -> Strin ...

  5. 微信js-sdk,选择图片,上传,下载到本地,php服务端

    //前端js代码<script> //客户端6.0.2 wx.config({ //debug:true, appId: "{pigcms:$signPackage.appId} ...

  6. Web前端浏览器兼容初探

    浏览器兼容是前端开发人员必须掌握的一个技能,但是初入前端的同学或者其他后台web开发同学往往容易选择忽略,而形成两个极端: 1 我最开始都是使用IE6,IE6上没问题,其它浏览器坑爹(多出现与前端后端 ...

  7. Linux(Centos)之安装tomcat并且部署Java Web项目(转)

    1.准备工作 a.下载tomcat linux的包,地址:http://tomcat.apache.org/download-80.cgi,我们下载的版本是8.0,下载方式如图:          b ...

  8. Symfony2 EventDispatcher组件

            一个插件系统中,A插件在不影响其它插件的前提下,添加新的方法,或者在一个方法运行前做一些准备工作,通过继承来实现扩展是很不容易的,由于插件之间的关联关系,A插件的改变也会使得关联的插件 ...

  9. 深入理解C#:编程技巧总结(二)

    原创文章,转载请注明出处! 以下总结参阅了:MSDN文档.<C#高级编程>.<C#本质论>.前辈们的博客等资料,如有不正确的地方,请帮忙及时指出!以免误导! 在上一篇 深入理解 ...

  10. Mongodb增加权限管理

     前言: 随着列式存储理念的成熟,越来越多的开发者开始接纳mongodb,hbase这类大储存的分布式列式数据库.特别是mongodb的这种快速搭建,快速使用特点,使其得到更多人的青睐.本人主要通过官 ...