Kindergarten
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 4787   Accepted: 2326

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

 
二分图找最大独立集
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; #define maxn 500 int g,b,m,ans;
bool f[maxn][maxn],vis[maxn];
int match[maxn]; bool dfs(int u) {
for(int i = g + ; i <= g + b; ++i) {
if(vis[i] || f[u][i] || u == i) continue;
vis[i] = ;
if(match[i] == - || dfs(match[i])) {
match[i] = u;
return true;
}
} return false;
}
void solve() {
for(int i = ; i <= g + b; ++i) match[i] = -; for(int i = ; i <= g; ++i) {
memset(vis,,sizeof(vis));
if(dfs(i)) ++ans;
}
}
int main()
{
// freopen("sw.in","r",stdin); int ca = ; while(~scanf("%d%d%d",&g,&b,&m)) {
memset(f,,sizeof(f));
if(!g && !b && !m) break;
ans = ; for(int i = ; i <= m; ++i) {
int x,y;
scanf("%d%d",&x,&y);
f[x][y + g] = ;
} solve(); // printf("ans = %d\n",ans); printf("Case %d: %d\n",++ca,g + b - ans); } return ;
}

POJ 3692的更多相关文章

  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(最大的使命)

    id=3692">Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4920   Ac ...

  5. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  6. POJ 3692 Kindergarten (补图是二分图的最大团问题)

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

  7. poj 3692 二分图最大匹配

    思路: 如果我们将认识的建边,求最大独立集就是互相不认识的人数.那么我们反过来,将不认识的建图,求最大独立集就是互相认识的人数. #include<cstdio> #include< ...

  8. POJ 3692 最大独立集

    题意:有G个女生,B个男生,所有的女生都互相认识,所有的男生都互相认识,还有N对男女,他们互相认识. 问从中选出最多的人数,是的他们全部互相认识. 思路:这道题的构图很巧妙,对于他的补图构图,对于所有 ...

  9. poj 3692 Kindergarten (最大独立集之逆匹配)

    Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...

随机推荐

  1. Android请求返回417解决办法

    今天碰到个很奇怪的问题,APP通过代理链接服务器会收到HTTP 417错误,经过网上查找发现是由于以下代码造成: HttpParams params = new BasicHttpParams(); ...

  2. SQL语句基础之 单表查找

    Sql语句之 单表查询 一.一般查询 1.查看表中的所有记录 以及 所有字段(属性) 语句 : select * from student; 2.只查看某些字段 语句:select sname,sex ...

  3. Debug.print的用法

    使用Debug.print可以用来更好的调试VBA程序 通过ALT+F11代开VBA编程窗口) 插入模块,接着在窗口中输入以下代码,按F5执行 Sub Excute() Debug.Print * + ...

  4. 【6.24-北京】AppCan移动开发者大会:最新议程曝光

    6.24,首届AppCan移动开发者大会将在北京国际会议中心召开. 大会以“平台之上,应用无限”为主题,旨在探讨在“互联网+双创”的大潮下,通过移动互联网技术.思维.模式,帮助开发者/创业者实现创新创 ...

  5. 什么是O/R Mapping(ORM)

    ORM,即Object-Relationl Mapping,它的作用是在关系型数据库和对象之间作一个映射,这样,我们在具体的操作数据库的时候,就不需要再去和复杂的SQL语句打交道,只要像平时操作对象一 ...

  6. C# 获取图片的EXIF 信息

    关于 EXIF 信息的介绍. 1  EXIF,是英文Exchangeable Image File(可交换图像文件)的缩写.EXIF是一种图像文件格式,只是文件的后缀名为jpg.EXIF信息是由数码相 ...

  7. Go原子计数

    通过原子计数可以在多线程情况下,对同一个数值进行加减操作,一般用于状态同步. 先看代码: package main import "fmt" import "time&q ...

  8. 取精华、去糟粕!适合iOS开发者的15大网站推荐

    iOS开发者若想使技艺达到炉火纯青的地步,就要不断借鉴他人的有益经验,紧跟新兴科技和工具的步伐.除了Apple的开发者中心,其他网站上的文章和资源也具备参考价值,若能学得一二,必能锦上添花.不过,时间 ...

  9. exception -----> Typedefs & Classes

    #include <exception> Typedefs exception_ptr 一种类型,描述了一个指向异常的指针 terminate_handler 一种类型,描述了一个适合作为 ...

  10. 检测到有潜在危险的 Request.Form 值。 说明: ASP.NET 在请求中检测到包含潜在危险的数据

    在请求方法的顶部添加        [ValidateInput(false)]就OK了 从客户端(Content=" sdfdddd ...")中检测到有潜在危险的 Reques ...