Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it was possible to form a committee of exactly P students that satisfies simultaneously t He conditions:
- Every student in the Committee represents a different course (a student can represent a course if he/she visits that cours E
- Each course have a representative in the Committee
Input
Your program should read sets of data from the STD input. The first line of the input contains the number of the data sets. Each data set was presented in the following format:
P N
Count1 Student 1 1 Student 1 2 ... Student 1 Count1
Count2 Student 2 1 Student 2 2 ... Student 2 Count2
...
COUNTP Student P 1 Student P 2 ... Student P COUNTP
The first line, each data set contains, positive integers separated by one blank:p (1 <= P <=)-The Numbe R of courses and N (1 <= n <=)-the number of students. The next P lines describe in sequence of the courses? From Course 1 to course P, each line describing a course. The description of course I was a line this starts with an integer Count I (0 <= Count i <= N) representing the Numbe R of Students visiting course I. Next, after a blank, you basis l FIND the Count I students, visiting the course, each of the consecutive separated by one blank. Students is numbered with the positive integers from 1 to N.
There is no blank lines between consecutive sets of data. Input data is correct.
Output
The result of the program is in the standard output. For each input data set, prints on a, "YES" if it is possible to form a committee and "NO" otherwise . There should not being any leading blanks at the start of the line.
Sample Input
23 33 1 2 32 1 21 13 32 1 32 1 31 1
Sample Output
YESNO
Test instructions: Enter P door class and N students, a total of 1-p lines, enter the total number of students in each row n, and then enter the student number, ask, can meet, each student only choose one course, each course has a student.
Idea: is the biggest matching water problem, I am very skeptical seniors This is the first to put the water on each OJ to the first 10, and then the back of the 6 to fly the kind of
#include <stdio.h>#include<string.h>#defineN 330#defineM 330intE[n][m],book[m],match[m];intn,m;intDfsintu) { inti; for(i =1; I <= m; i + +) { if(!book[i]&&E[u][i]) {Book[i]=1; if(!match[i]| |DFS (Match[i])) {Match[i]=u; return 1; } } } return 0;}intMain () {inti,j,t2,sum,t; scanf ("%d",&t); while(t--) {memset (match,0,sizeof(match)); Memset (E,0,sizeof(e)); scanf ("%d%d",&n,&m); for(i =1; I <= N; i + +) {scanf ("%d",&sum); for(j =1; J <= Sum; J + +) {scanf ("%d",&T2); E[I][T2]=1; }} sum=0; for(i =1; I <= N; i + +) {memset (book,0,sizeof(book)); if(Dfs (i)) sum++; } if(Sum = =N) printf ("yes\n"); Elseprintf ("no\n"); } return 0;}
"Binary Map matching Introductory topic 1" f-courses poj1469 "maximum match--Hungarian algorithm template problem"