Kindergarten
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 6956   Accepted: 3436

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 翻译:小朋友手拉手做游戏,现在老师希望从小朋友当中挑出一个集合,集合中的小朋友全都认识,那么这个集合最大是多少。
思路:显然是个最大独立集问题,只是男女小朋友关系图的补图的最大独立集,其补图中两个人相互连线意味着相互不认识,从图中挑出来的最大独立集就是题设要求的。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
const int N_MAX = ;
int V;//点的个数
vector<int>G[N_MAX];
int match[N_MAX];
bool used[N_MAX];
void add_edge(int u, int v) {
G[u].push_back(v);
G[v].push_back(u);
} bool dfs(int v) {
used[v] = true;
for (int i = ; i < G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
} int bipartite_matching() {
int res = ;
memset(match, -, sizeof(match));
for (int v = ; v < V; v++) {
if (match[v] < ) {
memset(used, , sizeof(used));
if (dfs(v))
res++;
}
}
return res;
}
bool vis[N_MAX][N_MAX];
int g, B, M;
int main() {
int Case = ;
while (scanf("%d%d%d",&g,&B,&M)&&g) {
Case++;
//0~g-1:girl
//g~g+B-1:boy
V = g + B;
memset(vis,,sizeof(vis));
for (int i = ; i < M; i++) {
int a, b;
scanf("%d%d",&a,&b);
a--, b--;
vis[a][g + b]=true;
}
for (int i=; i<g;i++) {
for (int j = g; j < V;j++) {
if (!vis[i][j]) {//建立原图的补图
add_edge(i,j);
}
}
}
printf("Case %d: %d\n",Case,V-bipartite_matching());
for (int i = ; i < V;i++) {
G[i].clear();
}
}
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(最大团问题)

    题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...

  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 (补图是二分图的最大团问题)

    题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...

  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 求补图的最大点独立集 头一次接触这样的做法

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5884   Accepted: 2877 Desc ...

随机推荐

  1. Fixed table

    废话不多说,直接代码. <!DOCTYPE> <html> <head> <meta charset="utf-8"/> <s ...

  2. C++实现动态数组

    实现一个动态数组,要求对于随机访问可以在常数时间完成,可以通过push_back向数据的尾部追加元素,可以通过pop_back删除尾部元素,能够满足常见的数组操作. LINE 2016年春招笔试   ...

  3. keras中的shape/input_shape

    在keras中,数据是以张量的形式表示的,张量的形状称之为shape,表示从最外层向量逐步到达最底层向量的降维解包过程.“维”的也叫“阶”,形状指的是维度数和每维的大小.比如,一个一阶的张量[1,2, ...

  4. core 下使用 autofac

    依赖注入小伙伴们比较常了,这里只说core 下autofac依赖注入的使用 ,不多费话,直接代码. 在 Startup.cs里 public void ConfigureServices(IServi ...

  5. msys2 使用指定boost

    pacman -S mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64- ...

  6. Memcache查看列出所有key方法

    Memcached查看列出所有key方法 测试的过程中,发现Memcached没有一个比较简单的方法可以直接象redis那样keys *列出所有的Session key,并根据key get对应的se ...

  7. 接口和类方法中的 SELF

    接口和类方法中的 SELF 由 王巍 (@ONEVCAT) 发布于 2015/06/10 我们在看一些接口的定义时,可能会注意到出现了首字母大写的 Self 出现在类型的位置上: protocol I ...

  8. React中 checkbox 与 label 标签的搭配

    用<label>标签替代checkbox的点击样子,点击<label>实际上就是点击checkbox checkbox的checked值会跟着一起变 <input typ ...

  9. RabbitMQ 初体验

    概述 RabbitMQ是一款消息队列中间件.他提供了几乎覆盖所有语言的SDK与文档,简直强大的不的了.要详细的去了解学习RabbitMQ,我建议还是看官方文档吧.http://www.rabbitmq ...

  10. mysql函数总结

    MySQL函数 MySQL数据库提供了很多函数包括: 数学函数:字符串函数:日期和时间函数:条件判断函数:系统信息函数:加密函数:格式化函数: 一.数学函数 数学函数主要用于处理数字,包括整型.浮点数 ...