POJ 3692-kindergarten (binary graph _ minimum vertex set)

Source: Internet
Author: User

Kindergarten
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 5477 Accepted: 2653

Description

In a kindergarten, there is a lot of kids. All girls of the kids know each other and all boys also know. In addition to, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need, all players know each other. 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 x B), which Is the number of girls, the number of boys and
The number of pairs of girl and boy know, respectively.
Each of the following M lines contains, integers x and Y (1≤ x≤g,1≤ y ≤B), which indicates that girl X and boy Y know each other.
The girls is numbered from 1 to G and the boys is numbered from 1 to B.

The last test was 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 an integer which is the max Imum number of kids the teacher can pick.

Sample Input

2 3 31 11 22 32 3 51 11 22 12 22 30 0 0

Sample Output

Case 1:3case 2:4

Test instructions: There are g girls, b boys, M inquiry, girls mutual understanding, boys to know each other, girls and boys have m relationship. The teacher wants to find the most people from the boys and girls to play games, these people ask to know each other.

Idea: It is also a new way to build a map. Boys know each other, girls know each other, there are some mutual understanding between boys and girls do not know, to find the most mutual understanding of the people to do the game, it is obvious that the maximum match is not feasible, the same group of people can not have a relationship, to the same group of people can not have a relationship, and the other group of relations, Only do not know the start, imagine the total number of people do not know the minimum number of mutual understanding is not the largest number of people ? So the picture is out.

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #include < iostream> #include <queue> #include <set>using namespace Std;int map[1010][1010];int vis[1010];int link[    1010];int g,b;int dfs (int u) {int i;            for (i=1;i<=b;i++) {if (!vis[i]&&map[u][i]) {vis[i]=1; if (link[i]==-1| |                DFS (Link[i])) {link[i]=u;            return 1; }}} return 0;}    int main () {int m;    int i,j;    int cnt=0;    int sum;    int A, B;        while (~SCANF ("%d%d%d", &g,&b,&m)) {cnt++;        sum=0;        memset (link,-1,sizeof (link));        if (g==0&&b==0&&m==0) break;        for (i=1;i<=g;i++) for (j=1;j<=b;j++) map[i][j]=1;            while (m--) {scanf ("%d%d", &a,&b);        map[a][b]=0;            } for (i=1;i<=g;i++) {memset (vis,0,sizeof (VIS)); if (DFS (i)) sum++;       }//printf ("%d---->", sum);    printf ("Case%d:%d\n", cnt,g+b-sum); } return 0;}


POJ 3692-kindergarten (binary graph _ minimum vertex set)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.