题目链接:
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. python3使用ip地址代理

    第一种IP地址代理方式from urllib import request if __name__ == "__main__": # 访问网址 url = 'http://www. ...

  2. Android-Kotlin-set/get方法的使用

    Student.kt package cn.kotlin.kotlin_oop04 open class Person { open var personName:String = "我是父 ...

  3. ThreadLocal实现线程级上下文

    一.ThreadLocal测试 package com.junge.threadlocal.context; /** * @author Administrator * */ public class ...

  4. ReLU 和sigmoid 函数对比

    详细对比请查看:http://www.zhihu.com/question/29021768/answer/43517930 . 激活函数的作用: 是为了增加神经网络模型的非线性.否则你想想,没有激活 ...

  5. 利用RGB-D数据进行人体检测 带dataset

    利用RGB-D数据进行人体检测 LucianoSpinello, Kai O. Arras 摘要 人体检测是机器人和智能系统中的重要问题.之前的研究工作使用摄像机和2D或3D测距器.本文中我们提出一种 ...

  6. JS学习笔记7_表单脚本

    1.获取表单及表单元素引用的方式 var mForm = document.forms[formName];获取表单引用 mForm.elements[elemName]获取表单元素,如有同名的,则得 ...

  7. ajax调用WebMethed返回处理请求时出错

    ajax post调用WebMethed报错,返回的信息如下: {“Message”:“处理请求时出错”,“StackTrace”:“”,“ExceptionType”:“”} 查了一下WebMeth ...

  8. Python isinstance 与 instance 的用法

    instance: instance 属于python2的关键字,python2中如果一个类没有继承自object, 那么实例化出来的对象就是instance类型,否则就是class类型. isins ...

  9. 堆排序(大顶堆、小顶堆)----C语言

    堆排序 之前的随笔写了栈(顺序栈.链式栈).队列(循环队列.链式队列).链表.二叉树,这次随笔来写堆 1.什么是堆? 堆是一种非线性结构,(本篇随笔主要分析堆的数组实现)可以把堆看作一个数组,也可以被 ...

  10. RabbitMQ在mac上的安装

    1.官网下载rabbitmq-server-3.6.3, 地址http://www.rabbitmq.com/install-standalone-mac.html.2.tar -zxvf rabbi ...