题目链接:
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. Tomcat数据源配置方法总结

    最近接触的数据表管理项目,涉及到了数据源配置,所以整理了一下配置方法: JNDI数据源统一都是在Tomcat下server.xml中配置的,根据应用范围的差别又分为一下几种方式: 第一种:配置单个应用 ...

  2. IT项目管理流程以及每个步骤用到的文档

    IT项目管理从大的方面可分为:1)项目启动阶段:2)项目计划阶段:3)项目的实施阶段:4)项目的结项阶段 1)项目启动阶段: 1.项目启动流程规范: 1.1项目启动的简介.目的和范围 1.2目的可行性 ...

  3. cocos 2dx 通过循环实现界面图形的摆放

    首先创建一个一维数组 this.starSprites = new Array(); 然后知道星星的间距和坐标后通过如下代码实现位置的摆放 for(var i = 0; i < 6; i++){ ...

  4. string转Date转回String(JAVA)

    String dateString = "2012-12-06 ";   SimpleDateFormat sdf = new SimpleDateFormat("yyy ...

  5. 利用 TFLearn 快速搭建经典深度学习模型

      利用 TFLearn 快速搭建经典深度学习模型 使用 TensorFlow 一个最大的好处是可以用各种运算符(Ops)灵活构建计算图,同时可以支持自定义运算符(见本公众号早期文章<Tenso ...

  6. 那些好用的阅读软件(Windows & Android)

    此文章已添加预览与更新,请您移步到我的新博客 http://t.cn/EXCiCTE 整个2018年就没写过几篇博文,所以写一篇文章算过年啦-哈哈-有部分软件因为年代原因,官网已经消失.或者网络上的资 ...

  7. Linux 安装JavaEE环境之jdk安装笔记

    1.安装jdk 先用xftp将jdk的压缩包上传到 /opt/ 2.在/usr/local/下使用命令mkdir java创建java目录 将jdk-7u79-linux-x64.gz解压缩至/usr ...

  8. cad.net之ACAD和GCAD环境变量获取

    #if AC2006 || AC2007 || AC2008 || AC2009 || AC2010 || AC2011 || AC2012 [System.Security.SuppressUnma ...

  9. 【入门推荐】SQL注入进行WebShell渗透测试的基础概览

    作者:zero 本文为SQL基本注入的进阶文章,如有任何疑问请查看: SQL基本注入演示:https://www.cnblogs.com/anbus/p/10082452.html 导语: 利用SQL ...

  10. Java入门-类HelloWorld是公共的,应在名为HelloWorld.java的文件中声明

    开始学习java了,搭好环境,notepad++中新建一个java文件,新建一个HelloWorld类, public class HelloWorld { public static void ma ...