传送门:http://poj.org/problem?id=3692

Language:
Kindergarten
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6831 Accepted: 3374
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 ≤ M ≤ G × 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

【解析】

题意:女孩们都互相认识,男孩们也都互相认识。有些男孩女孩互相认识,选出人数最多的互相认识的团体。

解法:求二分图的最大独立集。

如果我们选出的这些人两两互相认识,说明在一个图中这些点两两之间有连线,我们怎样找到这样一个图呢。

我们利用二分图的性质,将不认识的人连线。求最大独立集。最大独立集就是这个集合中的所有点两两之间没有连线。

没有连线就是互相认识。

最大独立集=所有的顶点个数-最大匹配。

【code】

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 200+10
int map[N][N],match[N];
bool vis[N];
int x,y,g,b,m,cnt,tim;
bool path(int x)
{
for(int i=;i<=b;i++)
{
if(!vis[i]&&!map[x][i])
{
vis[i]=;
if(!match[i]||path(match[i]))
{
match[i]=x;
return true;
}
}
}
return false;
}
int main()
{
while(scanf("%d%d%d",&g,&b,&m)&&g&&b&&m)
{
cnt=;//*注意清0
tim++;
memset(match,,sizeof(match));
memset(map,,sizeof(map));
for(int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=;
}
for(int i=;i<=g;i++)
{
memset(vis,,sizeof(vis));
if(path(i))
cnt++;
}
printf("Case %d: %d\n",tim,g+b-cnt);
}
return ;
}

最新文章

  1. [转]How do you create a custom AuthorizeAttribute in ASP.NET Core?
  2. python django基础(二)
  3. 自学 Java 怎么入门
  4. Python开发入门与实战10-事务
  5. poj 1730 Perfect Pth Powers
  6. Java读取文件夹大小的6种方法及代码
  7. javascript string对象的属性与方法
  8. 【转】Android Http Server
  9. Channel Allocation(DFS)
  10. JS定时器的使用--延时提示框
  11. Vue中的$set的使用
  12. [爬虫]Windows下如何安装python第三方库lxml
  13. Storm入门(一)原理介绍
  14. 24小时学通Linux内核总结篇(kconfig和Makefile &amp; 讲不出再见)
  15. Java反射《二》获取构造器
  16. deconvolution layer parameter setting
  17. CODE FESTIVAL 2017 qual B 题解
  18. 软工实践-Beta 冲刺 (2/7)
  19. 机器学习之路: 初识tensorflow 第一个程序
  20. unity 显示帧率

热门文章

  1. 2016/05/17 thinkphp3.2.2 分页的使用:①在Home下设置Publics文件夹或在thinkPHP下library的vender 把page.class.php 考贝进入 ②通过new 实例化方式调用 $page=new \Home\Publics\Page($total,3);
  2. lua例子getglobal()
  3. poj2349
  4. android菜鸟学习笔记22----ContentProvider(二)ContentObserver的简单使用
  5. git生成public key
  6. api 爬虫 避免相同 input 在信息未更新 情况下 重复请求重复
  7. thinkphp5, 省略index.php
  8. js格式化货币金额
  9. JVM性能优化, Part 1 ―― JVM简介
  10. windows10 Python2和Python3共存