首页 技术 正文
技术 2022年11月9日
0 收藏 750 点赞 3,787 浏览 1832 个字

题目链接:
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

2008 Asia Hefei Regional Contest Online by USTC

 /*
问题
输入女孩和男孩的个数和部分女孩和男孩的认识关系
计算并输出最多有多少个男孩和女孩是相互认识的 解题思路
属于图论中的最大团问题。了解了完全子图,意即该子图中任意两点相互连接,那么最大完全子图就是求解
最大完全子图的顶点数,也就是俗语说的最大团问题了。
再来说说如何求解最大完全子图顶点数
有一个定理:最大团=原图补图的最大独立集=顶点数-原图补图最大匹配数 那怎么什么是补图呢,其实就是原图的完全相反状态,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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902