COURSES
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 24919 |
|
Accepted: 9679 |
Description
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 Student1 1 Student1 2 ... Student1 Count1
Count2 Student2 1 Student2 2 ... Student2 Count2
...
COUNTP STUDENTP 1 studentp 2 ... STUDENTP 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
Source
Southeastern Europe 2000 Test instructions: P-gate Class n Students list each class there are several students on each course to have a class representative, ask you to find a class representative for each course. And each student can only be represented as a course class. Procedure: Naked * Hungarian algorithm
1#include <iostream>2 using namespacestd;3#include <cstdio>4#include <cstring>5#include <vector>6 Const intMAXN = +;7Vector <int>MAPS[MAXN];8 intn,m;9 intOK[MAXN];//Ok[i] On behalf of the node I can be pairedTen intMATCHED[MAXN];//Matched[i] Represents a paired object of the node I One BOOLMatchintx) { A for(intI=0; I<maps[x].size (); i++){ - intK =Maps[x][i]; - if(ok[k]==0){ theok[k]=1; - if(matched[k]==0|| Match (matched[k]) = =true){ -matched[k]=x; - return true; + } - } + } A return false; at } - intMain () { - intT; -scanf"%d",&t); - while(T--&&SCANF ("%d%d", &n,&m)! =EOF) { -memset (Matched,0,sizeof(matched)); in for(intI=0; i<=n;i++) - maps[i].clear (); to for(intI=1; i<=n;i++){ + intK; -scanf"%d",&k); the for(intj=0; j<k;j++){ * intp; $scanf"%d",&p);Panax Notoginseng Maps[i].push_back (p); - } the } + intAns =0; A for(intI=1; i<=n;i++){ theMemset (OK,0,sizeof(OK)); + if(Match (i) = =true) -ans+=1; $ } $ if(ans==N) { -printf"yes\n"); - } the Else -printf"no\n");Wuyi } the return 0; -}
POJ-1469 COURSES [binary map of Hungary algorithm]