1 #include<cstdio>
2 #include<vector>
3
4 using namespace std;
5
6 #define N1 100
7 #define N2 300
8
9 int match[N2];
10 vector<int> graph[N1];
11 bool visit[N2];
12
13 bool hungarian(int u){
14 for (auto i = graph[u].begin(); i != graph[u].end(); i++)
15 if (!visit[*i]){
16 visit[*i] = 1;
17 if (match[*i] == -1 || hungarian(match[*i])){
18 match[*i] = u;
19 return true;
20 }
21 }
22 return false;
23 }
24
25 int main(){
26 int m;
27 scanf("%d", &m);
28 for (int i = 0; i < m; i++){
29 int p, n;
30 bool flag = 0;
31 scanf("%d %d", &p, &n);
32 for (int j = 0; j < p; j++){
33 int num;
34 scanf("%d", &num);
35 graph[j].clear();
36 for (int l = 0; l < num; l++){
37 int student;
38 scanf("%d", &student);
39 graph[j].push_back(student - 1);
40 }
41 }
42 for (int j = 0; j < n; j++)
43 match[j] = -1;
44 for (int j = 0; j < p; j++){
45 for (int l = 0; l < n; l++)
46 visit[l] = 0;
47 if (!hungarian(j)){
48 flag = 1;
49 break;
50 }
51 }
52 if (flag)
53 printf("NO\n");
54 else
55 printf("YES\n");
56 }
57 return 0;
58 }