POJ3692 Kindergarten
来源:互联网 发布:sql语句转换成linq 编辑:程序博客网 时间:2024/05/16 18:31
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
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 longconst 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
- poj3692 Kindergarten
- POJ3692 HDU2458 Kindergarten
- POJ3692——Kindergarten
- POJ3692 Kindergarten 【最大独立集】
- poj3692 Kindergarten【最大独立集】
- POJ3692:Kindergarten(最大团)
- poj3692 Kindergarten 二分图最大独立集
- POJ3692 Kindergarten【二分图最大独立集】
- POJ3692——Kindergarten(最大二分匹配)
- poj3692
- poj3692
- poj3692
- POJ3692
- POJ3692——Kindergarten (二分图求最小顶点覆盖 (即最大匹配))
- Kindergarten
- [poj3692][匈牙利算法]
- JVM类加载机制
- 混合开发hybrid app(3)怎么增强webview安全功能 和 适配不同手机分辨率的html
- Mybatis调用存储过程
- Tomcat 8 启动startup.bat闪退的解决方法
- 写作建议
- POJ3692 Kindergarten
- sql 把字符串转成数字
- Linux 处理数据文件
- HBase HFile与Prefix Compression内部实现全解
- vue入门环境搭建
- Oracle 创建dblink
- poj-1014 多重背包问题
- 隐私窗口
- 以太坊区块和交易的存储结构分析