POJ3692 Kindergarten
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 6882 | Accepted: 3402 |
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
————————————————————————————————
题目的意思是给出n个男的m个女的,男的互相认识,女的互相认识,和k组关系,问能选出多少个人两两互相认识
思路:求最大团,最大团=补图的最大独立集=点数-补图的最大匹配
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; const int MAXN=1000;
int uN,vN; //u,v数目
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];
bool used[MAXN]; bool dfs(int u)
{
int v;
for(v=1; v<=vN; v++)
if(!g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
}
int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=1; u<=uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int m,u,v;
int q=1;
while(~scanf("%d%d%d",&uN,&vN,&m)&&(uN||vN||m))
{
memset(g,0,sizeof g);
for(int i=0;i<m;i++)
{
scanf("%d%d",&u,&v);
g[u][v]=1;
}
printf("Case %d: %d\n",q++,uN+vN-hungary());
}
return 0;
}
POJ3692 Kindergarten的更多相关文章
- POJ3692 Kindergarten 【最大独立集】
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5317 Accepted: 2589 Desc ...
- POJ3692 Kindergarten —— 二分图最大团
题目链接:http://poj.org/problem?id=3692 Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Sub ...
- poj 3692 Kindergarten (最大独立集)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4903 Accepted: 2387 Desc ...
- codeforces 484D D. Kindergarten(dp)
题目链接: D. Kindergarten time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- poj 3692 Kindergarten (最大独立集之逆匹配)
Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...
- POJ 3692 Kindergarten (二分图 最大团)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5660 Accepted: 2756 Desc ...
- POJ 3692:Kindergarten(最大的使命)
id=3692">Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4920 Ac ...
- Kindergarten Counting Game - UVa494
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva494.html 题目描述 Kin ...
随机推荐
- git 分支的创建和切换
每次提交,GIT 都会将他们串成一个时间线,截止到目前,只有一个时间线,GIT里叫这个分支为主分支,叫master,HEAD指向master,master指向提交,HEAD指向当前的分支. 一开始的时 ...
- 洛谷1288 取数游戏II
原题链接 因为保证有\(0\)权边,所以整个游戏实际上就是两条链. 很容易发现当先手距离\(0\)权边有奇数条边,那么必胜. 策略为:每次都将边上权值取光,逼迫后手向\(0\)权边靠拢.若此时后手不取 ...
- 伪静态的服务器配置-如何php为 Discuz! X2 配置伪静态
URL 静态化是一个有利于搜索引擎的设置,通过 URL 静态化,达到原来是动态的 PHP 页面转换为静态化的 HTML 页面,可以提高搜索引擎抓取,当然,这里的静态化是一种假静态,目的只是提高搜索 ...
- linux安全分析
history 查看历史命令 last | grep -i norco //最后一次登录时间
- 第二周java学习收获
JAVA学习第二周总结 教材学习内容总结 第二章:讲了标识符与关键字,以及基本数据类型:逻辑类型.整数类型.字符类型.浮点类型. 输入输出,System.in,System.out和数组. 第三章:运 ...
- nginx指令中的优化(配置文件)
nginx指令中的优化(配置文件)worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数.worker_cpu_affinity 00000001 0000 ...
- 在WebGrid中做 批量删除操作
一般的MVC WebGrid都是在每一行中加入 Edit Detail Delete 这些Link 去对每条记录去单独操作. 稍微研究了一下总结一个 做批量删除的办法. 1. 首先是在WebGrid中 ...
- 使用Hadoop API 压缩HDFS文件
下篇解压缩:使用Hadoop API 解压缩 HDFS文件 起因: 集群磁盘剩余空间不足. 删除了存储在HDFS上的,一定时间之前的中间结果,发现并不能释放太多空间,查看计算业务,发现,每天的日志存在 ...
- 2018.06.26「TJOI2018」数学计算(线段树)
描述 小豆现在有一个数 xxx ,初始值为 111 . 小豆有 QQQ 次操作,操作有两种类型: 111 $ m$ : x=x×mx=x×mx=x×m ,输出 xxx modmodmod MMM : ...
- Linux 下移植QT(1)---tslib 1.4.0移植
步骤1:下载工具包 如下图 链接在此,点我. 步骤2:将tslib文件放入Linux虚拟机中, 步骤3:解压源码 tar -xvf tslib-1.4.tar cd tslib-1.4 步骤4:执行a ...