#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
bool a[105][305];
bool used[305];
int mat[305];
int p,n;
bool crosspath(int k){
int i;
for(i=1;i<=n;i++)
if(a[k][i]==1&&used[i]==0){
used[i]=1;
if(mat[i]==0||crosspath(mat[i])){
mat[i]=k;
return 1;
}
}
return 0;
}
int main(){
int t;
int i,j;
int pi,stu;
scanf("%d",&t);
while(t--){
memset(a,0,sizeof(a));
memset(mat,0,sizeof(mat));
scanf("%d%d",&p,&n);
for(i=1;i<=p;i++){
scanf("%d",&pi);
for(j=1;j<=pi;j++){
scanf("%d",&stu);
a[i][stu]=1;
}
}
int match=0;
for(i=1;i<=p;i++){
memset(used,0,sizeof(used));
if(crosspath(i))
match++;
}
if(match==p)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
poj1469 COURSES
最新推荐文章于 2018-01-20 15:07:29 发布