二分图最大团-poj3692
来源:互联网 发布:ug软件好学吗 编辑:程序博客网 时间:2024/04/28 04:49
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第一次遇到最大团的问题。最大团=原图补图的最大独立集。下面是代码:#include<iostream>#include<set>#include<map>#include<vector>#include<queue>#include<cmath>#include<climits>#include<cstdio>#include<string>#include<cstring>#include<algorithm>typedef long long LL;using namespace std;int bg[205][205];int pre[205];bool vis[205];int G,B,M;bool dfs(int u){ vis[u]=1; for(int i=1; i<=B; i++) { if(!vis[i]&&bg[u][i]) { vis[i]=1; if(pre[i]==0||dfs(pre[i])) { pre[i]=u; return true; } } } return false;}int main(){ //freopen("in.txt","r",stdin); int x,y; int loop=1; while(cin>>G>>B>>M,G||B||M) { for(int i=0;i<=G;i++) fill(bg[i],bg[i]+B+1,1); memset(pre,0,sizeof(pre)); for(int i=0; i<M; i++) { cin>>x>>y; bg[x][y]=0; } int ans=0; for(int i=1; i<=G; i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) ++ans; } cout<<"Case "<<loop++<<": "<<G+B-ans<<endl; } return 0;}
- 二分图最大团-poj3692
- poj3692二分图最大团
- poj3692 补图二分图,最大团
- poj3692----图论---二分图最大团
- poj3692 二分图的最大团
- POJ3692 二分图最大团 最大独立集
- POJ3692:Kindergarten(最大团)
- 最大团&&二分图2
- 图论 二分图 最大团
- bzoj2744 二分图 最大团
- poj3692(二分图)
- Poj 3692 二分图最大团
- poj 3692 (二分图最大团)
- POJ 3692 Kindergarten (二分图 最大团)
- HDU3585-二分+最大团
- POJ3692 二分图匹配【入门】
- POJ2692 Kindergarten 最大团 + 补图二分图
- poj 3692 (二分图的最大团)
- C语言数组--快速排序
- static_cast, dynamic_cast, reinterpret_cast, const_cast区别比较
- IPicture使用代码
- eclipse几种版本的命名规则
- POJ 1195 - Mobile phones 二维树状数组(单点更新..区间查询)
- 二分图最大团-poj3692
- [5v]Java继承中父类与子类的初始化顺序
- 1.点亮1个led程序分析(C语言)
- 天灾
- 跟我一起写 Makefile(三)-陈皓
- POJ3903 最长递增子序列
- oracle 行转列(用函数和游标完成)
- 编译链接 头文件 与 库
- virtualbox 主机虚拟机互ping通,虚拟机可以上网 ssh连接设置