Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 24192 | Accepted: 9426 |
Description
- every student in the committee represents a different course (a student can represent a course if he/she visits that course)
- each course has a representative in the committee
Input
P N
Count1 Student Student ... Student
Count2 Student Student ... Student
...
CountP Student Student ... Student
The first line in each data set contains two positive integers separated by one blank: P (1 <= P <= 100) - the number of courses and N (1 <= N <= 300) - 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 is a line that starts with an integer Count i (0 <= Count i <= N) representing the number of students visiting course i. Next, after a blank, you抣l find the Count i students, visiting the course, each two consecutive separated by one blank. Students are numbered with the positive integers from 1 to N.
There are no blank lines between consecutive sets of data. Input data are correct.
Output
Sample Input
2 3 3 3 1 2 3 2 1 2 1 1 3 3 2 1 3 2 1 3 1 1
Sample Output
YES NO
题目大意:一些课一些人,组成一个集体,集体中每人代表每门不同的课,每门课在集体中有一名成员,问是否能组成这样的集体
思路:
这个题我们只需要求出二分图的最大匹配数,这样我们求出他们选的课程数,然后判断最大匹配数是否等于课程总数。
代码:
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 501 using namespace std; bool vis[N]; int t,w,n,m,x,ans,girl[N],map[N][N]; int read() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-';ch=getchar();} return x*f; } int find(int x) { ;i<=m;i++) { if(!vis[i]&&map[x][i]) { vis[i]=true; ||find(girl[i])) {girl[i]=x;;} } } ; } int main() { t=read(); while(t--) { ans=; memset(map,,sizeof(map)); n=read(),m=read(); ;i<=n;i++) { w=read(); ;} } if(m<n){printf("NO\n"); continue;} memset(girl,-,sizeof(girl)); ;i<=n;i++) { memset(vis,,sizeof(vis)); if(find(i)) ans++; } if(ans==n) printf("YES\n"); else printf("NO\n"); } ; }