1 #include <stdio.h>
2 #include <iostream>
3 #include <string.h>
4 #include <algorithm>
5 #include <vector>
6 #include <queue>
7 #include <utility>
8 #define MAXX 100010
9 using namespace std;
10 const int INF = 0x3f3f3f3f;
11 pair<vector<int>, int> x;
12 vector< vector<int> >bel(100010);
13 queue< vector<int> >qu;
14 int a[MAXX];
15 int cnt;
16
17 int findpush(int n)
18 {
19 int flag = 1;
20 for(int i = 1; i <= n; i++)
21 {
22 if(a[i] == 0)
23 {
24 flag = 0;
25 if(bel[i].size())
26 qu.push(bel[i]);
27 else
28 cnt--;
29 a[i] = INF;
30 }
31 }
32 return flag;
33 }
34
35 int main()
36 {
37 int T, n, t, ed;
38 scanf("%d", &T);
39 while(T--)
40 {
41 scanf("%d",&n);
42 cnt = n;
43
44 for(int i = 1; i <= n; i++)
45 a[i] = 0, bel[i].clear();
46 for(int i = 1; i <= n; i++)
47 {
48 scanf("%d", &t);
49 /* if(!t)
50 cnt--;*/
51 while(t--)
52 {
53 scanf("%d", &ed);
54 bel[ed].push_back(i);
55 a[i]++;
56 }
57 }
58 while(qu.empty())
59 {
60 int flag = findpush(n);
61 if(flag == 1)
62 {
63 if(cnt)
64 printf("No\n");
65 else printf("Yes\n");
66 break;
67 }
68 int temp = qu.size();
69 while(temp--)
70 {
71
72 for(int i = 0; i < (qu.front()).size(); i++)
73 {
74 a[(qu.front())[i] ]--;
75 }
76 qu.pop();
77 cnt--;
78 }
79 }
80 }
81 }