poj-3692(最大完全子图)
来源:互联网 发布:中科院心理研究所知乎 编辑:程序博客网 时间:2024/06/05 16:32
Memory Limit: 65536KTotal Submissions: 5335
Accepted: 2602
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题意: 有g个女孩,她们互相认识;有b个男孩,他们互相认识;有m对男女,他们互相认识。求最大的人数集合,集合里的人都相互认识。相关概念定理:
1.独立集:任意两点都不相连的顶点的集合
2.定理:最大独立集=顶点数-最大匹配边数(二分图当然也成立)
3.完全子图:任意两点都相连的顶点的集合(最大完全子图即最大团)
4.定理:最大团=原图补图的最大独立集
所以根据第四条可以看出在二分图中最大团问题可以方便解决,但在一般图中为NP问题。
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int line[510][510];int girl[510];int used[510];int x,y,g,b,m;bool find(int z){for(int i=1;i<=g;i++){if(line[z][i]&&!used[i]){used[i]=1;if(!girl[i]||find(girl[i])){girl[i]=z;return true;}}}return false;}int main(){int t=0;while(scanf("%d%d%d",&g,&b,&m)&&g&&b&&m){int sum=0;memset(girl,0,sizeof(girl));for(int i=1;i<=b;i++)for(int j=1;j<=g;j++){line[i][j]=1;}for(int z=1;z<=m;z++){scanf("%d%d",&x,&y);line[y][x]=0;}for(int a=1;a<=b;a++){memset(used,0,sizeof(used));if(find(a)) sum++;}printf("Case %d: ",++t);printf("%d\n",b+g-sum);}return 0;}
- poj -- 3692 Kindergarten (最大完全子图)
- poj-3692(最大完全子图)
- 最大完全子图
- POJ 2458 Kindergarten( 最大独立集(图) & 完全子图 )
- POJ3692 最大完全二分子图
- hihocoder week170分析---最大子完全图
- poj 3155 (最大密度子图)
- POJ 3155 最大密度子图
- POJ 3155 最大密度子图
- poj 2987 Firing【最大闭合子图】
- POJ 1050 最大子矩阵
- POJ 1768 最大子矩阵
- poj 1050最大子矩阵
- HDU 1505 DP 最大完全子矩阵
- HDU 1506 DP 最大完全子矩阵
- HDU 2870 DP 最大完全子矩阵
- HDU1505_City Game【最大完全子矩阵】
- HDU2870_Largest Submatrix【最大完全子矩阵】
- 关于Android通知栏的兼容问题
- Android控件之HorizontalScrollView 去掉滚动条
- ubuntu 显示或者隐藏 grub选择菜单
- android应用程序签名详解
- 局部代码块——构造代码块——静态代码块 (In Java)
- poj-3692(最大完全子图)
- 解决sublimeText3无法安装插件问题 -- There are no packages available for installation
- Fragment中调用父Activity中方法的简单方式
- Django SQL配置
- 好的产品也需要引爆点,如何找到它?
- 哥德巴赫猜想证明
- 【Docker】Docker1.3改动简介
- 阐述Linux动态库的显式调用
- What is the meaning of xmlns:tools in Android XML layout?