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. 程序windows上可以上传附件,部署到 linux服务器后出现 “上传目录 不可写” 怎么解决?

    这样的问题一般都是linux  下文件读写权限引起的,用 shell  命名到上传附件的目录(如 cd /data/www/project/upload/),然后执行 shell 文件权限设置: 例如 ...

  2. (转)SpringMVC学习(五)——SpringMVC的参数绑定

    http://blog.csdn.net/yerenyuan_pku/article/details/72511611 SpringMVC中的参数绑定还是蛮重要的,所以单独开一篇文章来讲解.本文所有案 ...

  3. 判断NumLock键和CapsLock键是否被锁定

    实现效果: 知识运用: AIP函数GetKeyState //针对已处理过的按键 在最近一次输入信息时 判断指定虚拟键的状态 intkey:预测试的虚拟键键码 实现代码: [DllImport(&qu ...

  4. Open Cascade:拓扑类型(Topo_DS)之间类型转换

    TopoDS_Edge aEdge = TopoDS::Edge(myAISShape->Shape()); TopoDS_Wire S1_wire = static_cast(S1); // ...

  5. 【Codeforces #228】Solutions

    http://codeforces.com/contest/389 重新把号刷到Div 1 准备ACM?(我这么菜还是玩玩算了……) 官方题解出的很快 Div2 A: 怎么做都行……随便找俩数减就可以 ...

  6. 第1节 flume:13、14、更多flume案例一,通过拦截器实现不同类型的数据区分

    1.6.flume案例一 1. 案例场景 A.B两台日志服务机器实时生产日志主要类型为access.log.nginx.log.web.log 现在要求: 把A.B 机器中的access.log.ng ...

  7. SniperOj-shorter-shellcode-x86

    shell-storm 这里可以有一些可以用的shellcode,不过自己写才是biner的骄傲 /奋斗 0x00 不会写shellcode(和一条咸鱼有什么区别/哭) 0x01 这题目前有俩种解法 ...

  8. Java异常 Exception类及其子类

    C语言时用if...else...来控制异常,Java语言所有的异常都可以用一个类来表示,不同类型的异常对应不同的子类异常,每个异常都对应一个异常类的对象. Java异常处理通过5个关键字try.ca ...

  9. iOS 第三方类库之MBProgressHUD

    github链接地址 MBProgressHUD是一个开源的第三方类库实现了很多种样式的提示框,类似Activity indicator,使用上简单.方便,并且可以对显示的内容进行自定义,功能很强大, ...

  10. centos7 parted 扩容

    (系统:vmware上的centos7.4 ,使用工具:parted分区命令.) 最近发现磁盘不够用了,需要加点.## WARNING ! 下面是实验过程,不代表生产环境.若有重要数据请操作前备份. ...