POJ 3692 二分图最大点独立集 解题报告
来源:互联网 发布:河南seo技术培训 编辑:程序博客网 时间:2024/05/16 07:59
Kindergarten
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
【解题报告】
代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define N 510int n,m,k,cas=0;int mp[N][N],cnt,head[N];struct Edge{int to,nxt;}e[N*N];int match[N],vis[N];void adde(int u,int v){ e[++cnt].to=v; e[cnt].nxt=head[u]; head[u]=cnt;}bool dfs(int u,int flag){ for(int i=head[u];~i;i=e[i].nxt) { int v=e[i].to; if(vis[v]==flag) continue; vis[v]=flag; if(!match[v]||dfs(match[v],flag)) { match[v]=u; return 1; } } return 0;}int main(){ while(scanf("%d%d%d",&n,&m,&k)&&n&&m&&k) { cnt=-1; memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); memset(match,0,sizeof(match)); memset(mp,0x7f,sizeof(mp)); for(int i=1;i<=k;++i) { int u,v;scanf("%d%d",&u,&v); mp[u][v]=0; } for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) if(mp[i][j]) adde(i,j); int ans=0; for(int i=1;i<=n;++i) { if(dfs(i,i)) ans++; } printf("Case %d: %d\n",++cas,n+m-ans); } return 0; }
- POJ 3692 二分图最大点独立集 解题报告
- POJ 3692 - Kindergarten 二分图的最大独立点集
- Poj 3692 Kindergarten 二分图最大独立点集
- Codeforces 808F 网络流最小割(二分图最大点权独立集) 解题报告
- poj 3692 二分图最大独立集
- poj 3692 Kindergarten(最大独立点集 + 二分图最大匹配)
- BZOJ 2744 [HEOI 2012] 二分图最大独立集 解题报告
- poj 2771 二分图最大独立集
- poj 1466 二分图 最大独立集
- poj 2594 二分图最大独立集
- poj 1068(二分图最大独立集)
- poj 3692 二分图最大独立集 Kindergarten
- poj 3692 Kindergarten 二分图 最大独立集
- poj 3692 Kindergarten(二分图匹配,最大独立集)
- POJ 3692 Kindergarten 二分图最大独立集
- POJ 3692 Kindergarten ( 最大独立点集 )
- poj 3692 最大独立点集
- POJ 1466 Girls and Boys(二分图匹配+拆点+最大独立集)
- Qt笔记_13
- 浅谈BI和大数据的关系
- 组合游戏/博弈论学习笔记
- 生活小记
- 小米运行时权限---代码中获取为granted,授权管理中显示为询问
- POJ 3692 二分图最大点独立集 解题报告
- java提高篇(43)--泛型
- 排序矩阵中的从小到大第k个数-LintCode
- HDU
- 简单 12 步理解 Python 装饰器
- MYSQL_ASSOC
- MySQL基本数据类型
- KMP学习
- Qt之浅析状态机QState