Question link: http://poj.org/problem? Id = 1274
Description
Farmer John completed his new barn just last week, complete with all the latest milking technology. unfortunately, due to engineering problems, all the stallin the new Barn are different. for the first week, Farmer John randomly assigned cows to stils, but it quickly became clear that any given cow was only willing to produce milk in certain stils. for the last week, Farmer John has been collecting data on which cows are willing to produce milk in which stils. A stall may be only assigned to one cow, and, of course, a cow may be only assigned to one stall.
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stils that is possible.
Input
The input parameter des several cases. for each case, the first line contains two integers, n (0 <= n <= 200) and M (0 <= m <= 200 ). n is the number of cows that farmer John has and m is the number of stils in the new Barn. each of the following n lines corresponds to a single cow. the first INTEGER (SI) on the line is the number of stallthat the cow is willing to produce milk in (0 <= SI <= m ). the subsequent Si integers on that line are the stils in which that cow is willing to produce milk. the stall numbers will be integers in the range (1 .. m), and no stall will be listed twice for a given cow.
Output
For each case, output a single line with a single integer, the maximum number of milk-producing stall assignments that can be made.
Sample Input
5 52 2 53 2 3 42 1 53 1 2 51 2
Sample output
4
Source
Usaco 40
Question:
There are nheaded cows, M barn, and each ox has its own favorite barn. They only eat food in their favorite barn and ask how many cows can eat at most!
The Code is as follows:
# Include <cstdio> # include <cstring> # include <algorithm> # include <iostream> using namespace STD; # define maxn 517int N; int ln, RN; int G [maxn] [maxn]; int linker [maxn]; bool used [maxn]; int DFS (int l) // find the augmented path {for (INT r = 1; r <= rn; r ++) {If (G [l] [r] &! Used [R]) {// find the augmented path, reverse used [R] = true; If (linker [R] =-1 | DFS (linker [R]) {linker [R] = L; return 1 ;}} return 0 ;}int Hungary () {int res = 0; memset (linker,-1, sizeof (linker); For (int l = 1; L <= ln; l ++) {memset (used, 0, sizeof (used )); if (DFS (L) RES ++;} return res;} int main () {int n, m; int TT, K; while (~ Scanf ("% d", & N, & M) {memset (G, 0, sizeof (g); For (INT I = 1; I <= N; I ++) {scanf ("% d", & K); For (Int J = 1; j <= K; j ++) {scanf ("% d", & TT); G [I] [TT] = 1 ;}} Ln = N; Rn = m; int ans = Hungary (); printf ("% d \ n", ANS);} return 0 ;}
Poj 1274 the perfect stall (maximum number of binary matching)