zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    港股实时行情数据
    A股实时行情数据
    A股历史行情数据 API 接口
    公募开放式基金历史数据
    历年奥运比赛数据 API 接口
    手机归属地查询 API 接口
    获取公众号文章封面 API 接口
    公众号头条文章 API 接口
    P3572 [POI2014]PTA-Little Bird
    CF1325D Ehab the Xorcist
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3602180.html
Copyright © 2011-2022 走看看