题目链接:
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. hdu 3910 Liang Guo Sha

    题目链接:hdu 3910 Liang Guo Sha 题目大意:Alice和Bob这两个小伙伴又发明了一种新游戏, 叫两国杀, 每个人手上有两张牌,“杀” 和“闪”, 然后有三个数值A,B和C, 当 ...

  2. Legal or Not HDU

    Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  3. [jquery] 遮罩弹窗,点击遮罩弹窗自动隐藏

    $("#id_sign_forbidden_win .c-content").click(function(event){ event.stopPropagation(); // ...

  4. Android-AndroidStudio加载工程方式-gradle文件夹

    例如:在其他地方,其他工作人员哪里的OpenGateDemo工程是OK的, 然后Copy到李四的电脑上运行是报错,其实所有的错误都和gradle有关: 第一步,李四电脑运行OpenGateDemo工程 ...

  5. Python学习--和 Oracle 交互(2)

    当在 mac 电脑上用 Python 读取 oracle 数据库中的中文时,有可能返回数据为“?” 解决方案: 在数据库操作的函数前添加以下代码, import sysreload(sys)sys.s ...

  6. Android常用库和插件

    下拉刷新 PullLoadMoreRecyclerView 实现RecyclerView下拉刷新和上拉加载更多以及RecyclerView线性.网格.瀑布流效果演示 https://github.co ...

  7. 【062新题】OCP 12c 062出现大量新题-15

    choose one In your Oracle 12c database, you plan to execute the command: SQL> CREATE TABLESPACE t ...

  8. safe close tcp connection

    https://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reli ...

  9. Shell - 简明Shell入门13 - 用户输入(UserInput)

    示例脚本及注释 1 - arguments #!/bin/bash if [ -n "$1" ];then # 验证参数是否传入 echo "The first para ...

  10. JAVA动态代理和方法拦截(使用CGLib实现AOP、方法拦截、委托)

    AOP用CGLib更简便.更可控. 动态代理的实现非常优雅. 实体类: public class SampleClass { public String MyFunction1(String inpu ...