Kindergarten
Time Limit: 2000MS   Memory Limit: 65536K
     

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

题意:在所有男孩都认识彼此与所有女孩都认识彼此的情况下,求一个人数最多的集合使得集合中任意两个人互相认识。

思路:顶点数=最大独立数+最小点覆盖数(最大匹配数);这里我们建立补图,补图有边的说明是不认识的,那么用最少的点(补图的最大二分匹配)将这些边去掉剩下的就全部互相认识了;

const int N=200+10;
int G,B,m,g[N][N],linked[N],v[N];
int dfs(int u)
{
for(int i=1; i<=B; i++)
if(!v[i]&&g[u][i])
{
v[i]=1;
if(linked[i]==-1||dfs(linked[i]))
{
linked[i]=u;
return 1;
}
}
return 0;
}
void hungary()
{
int ans=0;
memset(linked,-1,sizeof(linked));
for(int i=1; i<=G; i++)
{
memset(v,0,sizeof(v));
if(dfs(i)) ans++;
}
printf("%d\n",G+B-ans);
}
int main()
{
int t1=1;
while(~scanf("%d%d%d",&G,&B,&m))
{
if(G==m&&G==B&&B==0) break;
int x,y;
memset(g,-1,sizeof(g));
while(m--)
{
scanf("%d%d",&x,&y);
g[x][y]=0;
}
printf("Case %d: ",t1++);
hungary();
}
return 0;
}

关键在于建立补图然后求出最大二分匹配,只要构图和建模清晰了,剩下的就是裸模板了。

POJ-3692Kindergarten,求最大独立集!的更多相关文章

  1. poj1419 求最大独立集

    题目链接:http://poj.org/problem?id=1419 题意:求最大独立集 思路: 这里有一个定理: 最大独立集=补图的最大团最大团=补图的最大独立集 所以这里我们只要求给出的图的最大 ...

  2. uva12083 二分图 求最大独立集 转化为求最大匹配 由题意推出二分图

    这题大白书例题 : Frank 是一个思想有些保守的高中老师,有一次,他需要带一些学生出去旅行,但又怕其中一些学生在旅途中萌生爱意.为了降低这种事情的发生概率,他决定确保带出去的任意两个学生至少要满足 ...

  3. Poj(1466),最大独立集,匈牙利算法

    题目链接:http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total S ...

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

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

  5. Poj(2771),最大独立集

    题目链接:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K To ...

  6. POJ 1655 求树的重心

    POJ 1655 [题目链接]POJ 1655 [题目类型]求树的重心 &题意: 定义平衡数为去掉一个点其最大子树的结点个数,求给定树的最小平衡数和对应要删的点.其实就是求树的重心,找到一个点 ...

  7. poj 1966(求点连通度,边连通度的一类方法)

    题目链接:http://poj.org/problem?id=1966 思路:从网上找了一下大牛对于这类问题的总结:图的连通度问题是指:在图中删去部分元素(点或边),使得图中指定的两个点s和t不连通  ...

  8. hdu 1068 Girls and Boys(匈牙利算法求最大独立集)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. poj 3895(求无向图的最大简单环)

    题目链接:http://poj.org/problem?id=3895 思想很简单,就是dfs,并且用一个数组记录到该节点所走过的长度,然后如果遇到已经走过的,就说明存在环了, 更新一下ans. /* ...

  10. POJ 2480 求每一个数对于n的最大公约数的和

    这里是枚举每一个最大公约数p,那么最后求的是f(n) = sigma(p*phi(n/p))    phi()为欧拉函数 这里可以试着算一下,然后会发现这个是积性函数的 那么只要考虑每一类质数分开算, ...

随机推荐

  1. Tenegrad评价函数 分类: 图像处理 Opencv 2014-11-12 20:46 488人阅读 评论(0) 收藏

    Tenegrad函数式一种常用的图像清晰度评价函数,是一种基于梯度的函数. 在图像处理中,一般认为对焦好的图像具有更尖锐的边缘,故具有更大的梯度函数值. Tenegrad函数使用Sobel算子提取水平 ...

  2. iOS开发之邮件发送代码

    邮件发送功能是由MessageUI Framework提供的,这个框架是iPhone sdk中最简单的框.由一个类.一个视图控制器,一个protocol组成. 一.创建视图控制器: MFMailCom ...

  3. 转 SQL*PLUS中的替换变量(& &&)

    今天oracle support提供一个脚本,大致如下: PROMPT ROUTING_SEQUENCE_ID = &ROUT_SEQ_ID PROMPT OPERATION_SEQUENCE ...

  4. JUnit单元测试&注解

    ①测试方法上必须使用@Test进行修饰 ②测试方法必须使用public void 进行修饰,不能带任何的参数 ③新建一个源代码目录来存放我们的测试代码,即将测试代码和项目业务代码分开 ④测试类所在的包 ...

  5. leetcode 484. Find Permutation 思维题

    https://leetcode.com/contest/leetcode-weekly-contest-16a/problems/find-permutation/ 设原本的数字是0,那么按照它的D ...

  6. [转]Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application (3 of 10)

    本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/sorting-fi ...

  7. WPF学习11:基于MVVM Light 制作图形编辑工具(2)

    本文是WPF学习10:基于MVVM Light 制作图形编辑工具(1)的后续 这一次的目标是完成 两个任务. 画布 效果: 画布上,选择的方案是:直接以Image作为画布,使用RenderTarget ...

  8. 手机端左右滑动,不用写js(只有页面切换到移动端可以看)

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. reStructuredText学习

    reStructuredText学习====================2015年4月1日 学习的最好方法就是尽快动手开始.不断迭代,不断完善. reStructuredText学习v0.1版本. ...

  10. Farseer.net轻量级开源框架 中级篇:Cookies、Session、Request

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: 探究ORM(Mapping) 下一篇:Farseer.net轻量级开源框架 中级篇 ...