题目链接:
http://poj.org/problem?id=3692

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 ≤ MG × 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

 /*
问题
输入女孩和男孩的个数和部分女孩和男孩的认识关系
计算并输出最多有多少个男孩和女孩是相互认识的 解题思路
属于图论中的最大团问题。了解了完全子图,意即该子图中任意两点相互连接,那么最大完全子图就是求解
最大完全子图的顶点数,也就是俗语说的最大团问题了。
再来说说如何求解最大完全子图顶点数
有一个定理:最大团=原图补图的最大独立集=顶点数-原图补图最大匹配数 那怎么什么是补图呢,其实就是原图的完全相反状态,1就是0,0就是1
所以和求原图的最大独立集算法中只需将注释出改一个相反即可。
*/
#include<cstdio>
#include<cstring> int g,b,m;
int e[][],cx[],cy[],bk[];
int maxmatch();
int path(int u);
int main()
{
int t1,t2,t=,i;
while(scanf("%d%d%d",&g,&b,&m) == && g+b+m != ){
memset(e,,sizeof(int)**);
for(i=;i<=m;i++){
scanf("%d%d",&t1,&t2);
e[t1][t2]=;
}
printf("Case %d: %d\n",t++,g+b-maxmatch());
}
return ;
}
int maxmatch()
{
int i,ans=;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
for(i=;i<=g;i++){
memset(bk,,sizeof(bk));
ans += path(i);
}
return ans;
}
int path(int u)
{
int i;
for(i=;i<=b;i++){
if(!e[u][i] && !bk[i]){//求补图的最大独立集,所以只需将原来的e[u][i]变为!e[u][i]即可
bk[i]=;
if(cy[i] == - || path(cy[i])){
cy[i]=u;
cx[u]=i;
return ;
}
}
}
return ;
}

POJ 3692 Kindergarten(最大团问题)的更多相关文章

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

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

  2. POJ 3692 Kindergarten (补图是二分图的最大团问题)

    题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...

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

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

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

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

  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

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6956   Accepted: 3436 Desc ...

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

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

  8. POJ 3692:Kindergarten(最大的使命)

    id=3692">Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4920   Ac ...

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

    题目链接 题意 已知班级有g个女孩和b个男孩,所有女生之间都相互认识,所有男生之间也相互认识,给出m对关系表示哪个女孩与哪个男孩认识.现在要选择一些学生来组成一个集合,使得里面所有人都认识,求此集合最 ...

随机推荐

  1. appcompat_v7报错

    appcompat_v7如果报找不到资源,value-xx出错.一般就是因为appcompat_v7的版本问题,直接修改api版本至appcompat_v7对应value的最高版本. 我的v7包最高对 ...

  2. 第一天:javascript实现界面运算及循环语句跳转语句

    文档位置:untitled3(c:\user\dell\WebstormProjects\untitled3\testjstry0.html) 知识点1: 1.新创建html文件,编辑文档如下: &l ...

  3. 软件测试实践平台(Mooctest)FAQ

    0. 背景 我们在<软件测试技术>课程使用 MOOCTEST (mooctest.net) 作为课程的实践教学平台. 在教学过程中学生们遇到了一些问题,本文将一一总结. 注意:本文在解决问 ...

  4. ubuntu 安装CUDA 8.0

    安装CUDA 8.0 1) 在终端运行指令 sudo sh cuda_8.0.44_linux.run --no-opengl-libs 不加这个选项会进入循环登陆 2) 之后是一些提示信息,输入ac ...

  5. Easyui datagrid绑定数据,新增,修改,删除方法(一)

    @{ ViewBag.Title = "UsersList"; } <script type="text/javascript"> $(functi ...

  6. 【BZOJ3709】 [PA2014]Bohater(贪心)

    传送门 BZOJ Solution 考虑如果可以回血肯定要打,那么就是按照伤害值从小到大排个序能打就打,不能打就\(NIE\). 接着看不能够回血的,emmm,把这个过程反着看一下就是打一个怪扣\(a ...

  7. Unity LuaFramework LuaBundleMode

    设置 AppConst.cs 中的 LuaBundleMode 为 true,开启 Lua 代码 AssetBundle 模式. 启动程序报错,Moudle XXX not found. 我在 Ass ...

  8. 安装openvpn

    1.安装服务器端openvpn  yum install -y openvpn easy-rsa 如果已存在的yum源中找不安装文件,则可通过以下安装epel yum源 rpm -ivh http:/ ...

  9. ArrayList的源码分析

    在项目中经常会用到list集合来存储数据,而其中ArrayList是用的最多的的一个集合,这篇博文主要简单介绍ArrayList的源码分析,基于JDK1.7: 这里主要介绍 集合 的属性,构造器,和方 ...

  10. flask_mysql入库

    mysql 的入库和MongoDB的有一点点的区别 不过都很重要,都必须要掌握的技能, 现在我来演示一下mysql入库的过程: 首先  我们要导包,这是必不可少的一部分,都不用我说了吧 #导报 imp ...