直接模板
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <string>
#define N 23541
using namespace std;
int t[305][305];
int girl[305],boy[305];
int visit[305];
int num,p,n,student,istud;
int dfs(int u)
{
for(int i=1;i<=n;i++)
{
if(t[u][i]&&!visit[i])
{
visit[i]=1;
if(boy[i]==0||dfs(boy[i]))
{
girl[u]=i;
boy[i]=u;
return 1;
}
}
}
return 0;
}
bool maxmatch()
{
memset(girl,0,sizeof(girl));
memset(boy,0,sizeof(boy));
for(int i=1;i<=p;i++)
{
if(girl[i]==0)
{
memset(visit,0,sizeof(visit));
if(dfs(i)==0)
return false;
}
}
return true;
}
int main()
{
cin>>num;
while(num--)
{
memset(t,0,sizeof(t));
cin>>p>>n;
for(int i=1;i<=p;i++)
{
cin>>student;
while(student--)
{
cin>>istud;
t[i][istud]=1;
}
}
if(maxmatch()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}