poj 3692 Kindergarten 【最大团 = 补图最大独立集 = 补图节点数 - 补图最大匹配】
来源:互联网 发布:淘宝发空包什么意思 编辑:程序博客网 时间:2024/04/29 22:59
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 31 11 22 32 3 51 11 22 12 22 30 0 0
Sample Output
Case 1: 3Case 2: 4
题意:给定一个无向图,让你求它的最大团。
思路:最大团 = 补图最大独立集 = 补图节点数 - 补图最大匹配。
因为B、G弄反了,WA2次。。。
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (200+10)#define MAXM (50000000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;int B, G, M;int Map[MAXN][MAXN];bool used[MAXN];int match[MAXN];int DFS(int u){ for(int i = 1; i <= B; i++) { if(!used[i] && Map[u][i] == 0) { used[i] = true; if(match[i] == -1 || DFS(match[i])) { match[i] = u; return 1; } } } return 0;}int main(){ int kcase = 1; while(scanf("%d%d%d", &G, &B, &M) != EOF) { if(B == 0 && G == 0 && M == 0) break; CLR(Map, 0); for(int i = 1; i <= M; i++) { int a, b; Ri(a); Ri(b); Map[a][b] = 1; } CLR(match, -1); int ans = 0; for(int i = 1; i <= G; i++) { CLR(used, false); ans += DFS(i); } printf("Case %d: %d\n", kcase++, B+G-ans); } return 0;}
- poj 3692 Kindergarten 【最大团 = 补图最大独立集 = 补图节点数 - 补图最大匹配】
- HDU 2458 最大团个数=顶点数 - 补图最大匹配数 二分匹配
- POJ 1419 Graph Coloring(最大独立集/补图的最大团)
- POJ 3692 Kindergarten (补图的最大独立集||匈牙利算法)
- POJ 3692 Kindergarten(最大匹配+匈牙利算法+补图思想)
- POJ2692 Kindergarten 最大团 + 补图二分图
- POJ 3692 Kindergarten 最大团->最大独立集
- poj 3692 Kindergarten(二分图匹配,最大独立集)
- poj 3692 最大团(二分图匹配,最大独立集)
- poj 3692(浅谈二分图最大匹配求最大独立集在解决最大团问题中的应用)
- poj 3692 Kindergarten(最大独立点集 + 二分图最大匹配)
- poj3692 补图二分图,最大团
- Kindergarten(求二分图最大团转化为求补图的最大独立集(再转化为匈牙利算法求最大匹配))
- poj 3692 Kindergarten(最大团,二分图匹配)
- poj 3692 二分图最大独立集 Kindergarten
- poj 3692 Kindergarten 二分图 最大独立集
- POJ 3692 - Kindergarten 二分图的最大独立点集
- Poj 3692 Kindergarten 二分图最大独立点集
- 自定义spring schema简化与canal集成
- 诚风老师-直销十三步走
- 正则pumping lemma和infeasible path
- Broadcast广播的使用
- iOS.swift 如何设置tableview禁止上下滚动
- poj 3692 Kindergarten 【最大团 = 补图最大独立集 = 补图节点数 - 补图最大匹配】
- 一个mapreduce同时实现计数与排序
- 排序算法-插入排序_直接插入排序
- MySQL 5.7 zip版 安装过程
- HDU 5527(Too Rich-贪心)
- [273]Integer to English Words
- nyoj--528--找球号(三)(位运算&&set)
- 2015-2016 ACM ICPC Baltic Selection Contest [解题报告]
- Linux终端bash美化教程