题目链接:http://poj.org/problem?id=3692

Kindergarten
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 7371   Accepted: 3636

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
GB (1 ≤ GB ≤ 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

题解:

最大团 = 总体 - 补图的最大独立集。

证明:最大独立集,即两两没有联系。那么它的补图,就是两两都有联系。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
const int INF = 2e9;
const int MOD = 1e9+;
const int MAXN = +; int uN, vN;
int M[MAXN][MAXN], link[MAXN];
bool vis[MAXN]; bool dfs(int u)
{
for(int i = ; i<=vN; i++)
if(M[u][i] && !vis[i])
{
vis[i] = true;
if(link[i]==- || dfs(link[i]))
{
link[i] = u;
return true;
}
}
return false;
} int hungary()
{
int ret = ;
memset(link, -, sizeof(link));
for(int i = ; i<=uN; i++)
{
memset(vis, , sizeof(vis));
if(dfs(i)) ret++;
}
return ret;
} int main()
{
int T, m, kase = ;
while(scanf("%d%d%d", &uN, &vN, &m)&& (uN||vN||m))
{
memset(M, true, sizeof(M));
for(int i = ; i<=m; i++)
{
int u, v;
scanf("%d%d", &u, &v);
M[u][v] = false;
} int cnt = hungary();
printf("Case %d: %d\n", ++kase, uN+vN-cnt);
}
}

最新文章

  1. oracle 关键字
  2. ASP.NET 中HTML和Form辅助方法
  3. css图片叠加和底部定位
  4. 2.1 CMMI2级——7个PA简述
  5. UseFul Collection
  6. [Mysql] mysql临时表corrupt
  7. python元类
  8. 【Android车载系统 News | Tech 1】News 谷歌开发车载Android系统 2014-12-19
  9. js调用ASP.NET打印代码
  10. mybatis3.4测试CRUD
  11. redux-form的学习笔记二--实现表单的同步验证
  12. H5与Native交互之JSBridge技术
  13. ThinkingInJava 学习 之 0000005 访问权限控制
  14. 转 /etc/ld.so.conf.d/目录下文件的作用
  15. sklearn中SVM调参说明
  16. zkSNARK 零知识验证
  17. mybatis - maven - eclipse 坑爹问题: No suitable driver found for http://maven.apache.org
  18. 数据恢复软Extundelete
  19. 3星|《科技投资新时代》:TMT行业资讯汇编
  20. Linux查看系统与内核信息(uname、file和lsb_release -a)

热门文章

  1. tiles框架的definition讲解
  2. Java学习之Math类理解
  3. angularjs自己总结
  4. Codeforces Round #211 (Div. 2)-D. Renting Bikes,二分!感谢队友出思路!
  5. [luoguP1947] 笨笨当粉刷匠_NOI导刊2011提高(10)(DP)
  6. Codeforces 892 D.Gluttony
  7. CodeForces 599C Day at the Beach
  8. Access数据库密码破解 C#
  9. otl_stream流相关绑定变量
  10. hp 88a加粉