Kindergarten
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 5317 |
|
Accepted: 2589 |
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
Source
Asia Hefei Regional Contest Online by USTCTest instructions: in the kindergarten. All the boys knew each other, and the girls knew each other. Some boys are acquainted with some girls, and now given these cognitive relationships, choosing one of the largest set of points allows everyone inside to know each other. Puzzle: The independent set of the binary graph is only from the binary graph G = (x, y; E) Select some points v belongs to {X, Y}. Makes the point set V free from the edge link between two points. And the maximal independent set model of the binary graph is the max|v| to be obtained.
There are, for example, the following formula: maximum number of independent set vertices = number of nodes (| x|+| y|)-The maximum number of matches.
#include <stdio.h> #include <string.h> #define MAXN 205bool G[MAXN][MAXN], Visy[maxn];int GIRL[MAXN], boy[ Maxn];int G, B, M, cas = 1;void getmap () {int u, v; memset (g, 0, sizeof (g)); while (m--) {scanf ("%d%d", &u, &v); G[U][V] = true; }}int findpath (int x) {int i; for (i = 1; I <= b; ++i) {if (! G[x][i] &&!visy[i]) {visy[i] = 1; if (boy[i] = = 1 | | findpath (boy[i])) {boy[i] = x; return 1; }}} return 0;} int Maxmatch () {int I, ans = 0; Memset (Girl,-1, sizeof (girl)); memset (Boy,-1, sizeof); for (i = 1; I <= g; ++i) {memset (Visy, 0, sizeof (Visy)); Ans + = Findpath (i); } return ans; void Solve () {printf ("Case%d:%d\n", cas++, G + b-maxmatch ());} int main () {while (scanf ("%d%d%d", &g, &b, &m), g | b | m) {getmap (); Solve (); } return 0;}
POJ3692 Kindergarten "Maximum independent set"