POJ3692 Kindergarten —— 二分图最大团
题目链接:http://poj.org/problem?id=3692
| 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
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
题解:
最大团 = 总体 - 补图的最大独立集。
证明:最大独立集,即两两没有联系。那么它的补图,就是两两都有联系。
代码如下:
#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);
}
}
POJ3692 Kindergarten —— 二分图最大团的更多相关文章
- POJ 3692 Kindergarten (二分图 最大团)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5660 Accepted: 2756 Desc ...
- POJ 3692:Kindergarten(二分图最大团)
题目链接 题意 已知班级有g个女孩和b个男孩,所有女生之间都相互认识,所有男生之间也相互认识,给出m对关系表示哪个女孩与哪个男孩认识.现在要选择一些学生来组成一个集合,使得里面所有人都认识,求此集合最 ...
- POJ3692 Kindergarten 【最大独立集】
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5317 Accepted: 2589 Desc ...
- POJ3692 Kindergarten
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6882 Accepted: 3402 Desc ...
- POJ 3692 Kindergarten(最大团问题)
题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...
- 【BZOJ 2744】【HEOI2012】朋友圈
题目链接: TP 题解: 对于A国,我们发现,最大团一定不大于2.对于B国,发现同奇偶性点之间都有边,不同奇偶性之间可能有边,也就是说对于B国是一个二分图最大团,也就是求B国补图的二分图最大独立集.然 ...
- POJ 3692 Kindergarten (补图是二分图的最大团问题)
题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...
- BZOJ - 2744 朋友圈 (二分图上的最大团)
[题目大意] 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最大数目.两 ...
- 【BZOJ 2744】 2744: [HEOI2012]朋友圈 (最大团,二分图匹配,构图)
2744: [HEOI2012]朋友圈 Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他 ...
随机推荐
- C#基于引用创建单链表
在C语言,单链表的实现依赖指针,指针用来指向节点,那么,用C#实现,自然就想到引用,节点的引用不就类似于指向Node的指针嘛
- Leetcode 309.最佳买卖股票时机含冷冻期
最佳买卖股票时机含冷冻期 给定一个整数数组,其中第 i 个元素代表了第 i 天的股票价格. 设计一个算法计算出最大利润.在满足以下约束条件下,你可以尽可能地完成更多的交易(多次买卖一支股票): 你不 ...
- 76. Spring Boot完美解决(406)Could not find acceptable representation原因及解决方法
[原创文章] 使用Spring Boot的Web项目,处理/login请求的控制器方法(该方法会返回JSON格式的数据).此时如果访问localhost:8080/login.html, ...
- 转载:shell脚本之前的基础知识
转载地址:http://www.92csz.com/study/linux/12.htm 第十二章 学习 shell脚本之前的基础知识 日常的linux系统管理工作中必不可少的就是shell脚本,如果 ...
- 【BZOJ2560】串珠子(状压DP,容斥原理)
题意: 铭铭有n个十分漂亮的珠子和若干根颜色不同的绳子.现在铭铭想用绳子把所有的珠子连接成一个整体.现在已知所有珠子互不相同,用整数1到n编号.对于第i个珠子和第j个珠子,可以选择不用绳子连接,或者在 ...
- 内存管理(——高质量程序设计语言C/C++第16章)
内存的分配方式: 1.静态存储区分配:全局变量,static变量等,在程序编译时已经分配了存储内存,在程序运行的整个期间一直存在 2.程序的堆栈上:程序的局部变量,包括程序的形参等,只存在于程序的运行 ...
- HDU 1024 Max Sum Plus Plus【DP,最大m子段和】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1024 题意: 给定序列,给定m,求m个子段的最大和. 分析: 设dp[i][j]为以第j个元素结尾的 ...
- 组队训练2 回放(转载至cxhscst2's blog)
2017/3/4 12:00-17:00 Solve 9 / 13 Penalty 717 练习赛过程回放: 开场5分中J题签到(cst) 12分钟时qw签到A 这时qw继续开写M,WA,检查代码. ...
- 洛谷——P2068 统计和
P2068 统计和 题目描述 给定一个长度为n(n<=100000),初始值都为0的序列,x(x<=10000)次的修改某些位置上的数字,每次加上一个数,然后提出y (y<=1000 ...
- 利用Cufon技术渲染文字的简单示例
Cufon是一种能够根据指定的字体渲染文字的技术.今天试用了下,主要有几个步骤: 1.下载Cufon.js(http://cufon.shoqolate.com/generate/) 2.获取需要渲染 ...