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
  • 相关阅读:
    CVS简介
    快捷搭建JavaWeb开发环境
    局域网Win7 SVN 服务器搭建以及使用(原创)
    给自己 一个方向,让自己不再迷茫
    SQL Server2005安装配置以及测试
    Oracle中表结构和表内容复制
    Myeclipse8.5 svn插件安装两种方式
    Oracle中错误代码ORA02292 违反了完整性约束条件解决
    JSP中字符编码转换问题
    C# sealed关键词
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3602180.html
Copyright © 2011-2022 走看看