首页 > 其他 > 详细

POJ 3692

时间:2014-03-16 00:23:17      阅读:449      评论:0      收藏:0      [点我收藏+]
Kindergarten
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 4787   Accepted: 2326

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 ≤ MG × 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

Source

 
二分图找最大独立集
 
bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 
 7 using namespace std;
 8 
 9 #define maxn 500
10 
11 int g,b,m,ans;
12 bool f[maxn][maxn],vis[maxn];
13 int match[maxn];
14 
15 
16 bool dfs(int u) {
17         for(int i = g + 1; i <= g + b; ++i) {
18                 if(vis[i] || f[u][i] || u == i) continue;
19                 vis[i] = 1;
20                 if(match[i] == -1 || dfs(match[i])) {
21                         match[i] = u;
22                         return true;
23                 }
24         }
25 
26         return false;
27 }
28 void solve() {
29         for(int i = 1; i <= g + b; ++i) match[i] = -1;
30 
31         for(int i = 1; i <= g; ++i) {
32                 memset(vis,0,sizeof(vis));
33                 if(dfs(i)) ++ans;
34         }
35 }
36 int main()
37 {
38    // freopen("sw.in","r",stdin);
39 
40     int ca = 0;
41 
42     while(~scanf("%d%d%d",&g,&b,&m)) {
43             memset(f,0,sizeof(f));
44             if(!g && !b && !m) break;
45             ans = 0;
46 
47             for(int i = 1; i <= m; ++i) {
48                     int x,y;
49                     scanf("%d%d",&x,&y);
50                     f[x][y + g] = 1;
51             }
52 
53             solve();
54 
55            // printf("ans = %d\n",ans);
56 
57             printf("Case %d: %d\n",++ca,g + b - ans);
58 
59 
60     }
61 
62     return 0;
63 }
View Code

 

POJ 3692,布布扣,bubuko.com

POJ 3692

原文:http://www.cnblogs.com/hyxsolitude/p/3602180.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!