#include <stdio.h>
#include <string.h>
#define M 311
int m,n;
int map[M][M], match[M], chk[M];
int find(int p)
{
int i;
for(i=1;i<=n;i++)
if( map[p][i] && chk[i]==0 )
{
chk[i]=1;
if( match[i]==0 || find( match[i] ) )
{
match[i]=p;
return 1;
}
}
return 0;
}
int solve()
{
int i,res;
for(i=1,res=0; i<=m; i++)
{
memset(chk,0,sizeof(chk));
res+=find(i);
}
return res;
}
int main()
{
// freopen("in","r",stdin);
// freopen("out","w",stdout);
int k,i,x,t,r;
scanf("%d",&t);
while( t-- )
{
scanf("%d%d",&m,&n);
memset(map,0,sizeof(map));
memset(match,0,sizeof(match));
for(i=1;i<=m;i++)
{
scanf("%d",&k);
for(r=0;r<k;r++)
{
scanf("%d",&x);
map[i][x]=1;
}
}
if( solve()==m )
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
hdu 1083
最新推荐文章于 2021-09-12 13:26:16 发布