Test instructions
For you P-gate course and N students, a student can choose 0, 1, or more courses, now requires a set of P students, meet the following 2 conditions:
1. Each student chooses a different course
2. Each course has a different representation
If satisfied, the output is yes
Otherwise, the output no
#include <cstdio>#include<iostream>#include<cstring>#defineM 310using namespacestd;intUsed[m],belong[m],a[m][m],p,n;intFindinti) { for(intj=1; j<=n;j++) if(!used[j]&&A[i][j]) {Used[j]=1; if(!belong[j]| |find (Belong[j])) {Belong[j]=i; return 1; } } return 0;}intMain () {intT; scanf ("%d",&T); while(t--) {memset (A,0,sizeof(a)); Memset (Belong,0,sizeof(belong)); memset (Used,0,sizeof(used)); scanf ("%d%d",&p,&N); for(intI=1; i<=p;i++) { intx, y; scanf ("%d",&x); for(intj=1; j<=x;j++) {scanf ("%d",&y); A[i][y]=1; } } inttot=0; for(intI=1; i<=p;i++) if(Find (i)) {memset (used,0,sizeof(used)); Tot++; } if(tot==p) printf ("yes\n"); Elseprintf"no\n"); } return 0;}
View Code
COURSES (POJ 1249)