• POJ 3692


    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

     
    二分图找最大独立集
     
     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
    ",ans);
    56 
    57             printf("Case %d: %d
    ",++ca,g + b - ans);
    58 
    59 
    60     }
    61 
    62     return 0;
    63 }
    View Code
  • 相关阅读:
    基本类型传递值与引用类型传递值的区别
    01 基本类型的赋值与引用类型赋值的区别
    模仿51cto搜索框
    使用map将字数组里的对象重新组装
    01day 表单组件 动态绑定变量 导航组件 地图组件 view text是否可以复制 button 上下滚动组件
    POJ1321棋盘问题(暴搜)
    Codeforces Round #620 (Div. 2) C. Air Conditioner
    Codeforces Round #620 (Div. 2) B. Longest Palindrome
    Codeforces Round #620 (Div. 2) A. Two Rabbits
    Codeforces Round #619 (Div. 2) Ayoub's function
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3602180.html
Copyright © 2020-2023  润新知