Problem B

Statement
Copy Copied
B. Merging the Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given $$$n$$$ sets $$$S_1,S_2,\ldots,S_n$$$, where each element in the sets is an integer between $$$1$$$ and $$$m$$$.You want to choose some of the sets (possibly none or all), such that every integer between $$$1$$$ and $$$m$$$ is included in at least one of the chosen sets.You have to determine whether there exist at least three ways to choose the sets.InputEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 5\cdot 10^4$$$, $$$1\le m \leq 10^5$$$) — the number of sets and the upper bound of the integers in the sets.Then $$$n$$$ lines follow, the $$$i$$$-th line first containing an integer $$$l_i$$$ ($$$1\le l_i\le m$$$) — the size of set $$$S_i$$$. Then $$$l_i$$$ integers $$$S_{i,1}, S_{i,2}, \ldots, S_{i, l_i}$$$ follow in the same line ($$$1\le S_{i,1} < S_{i,2} < \cdots < S_{i, l_i}\le m$$$) — the elements of set $$$S_i$$$.Let $$$L=\sum\limits_{i=1}^n l_i$$$. It is guaranteed that:  The sum of $$$n$$$ over all test cases does not exceed $$$5\cdot 10^4$$$;  The sum of $$$m$$$ over all test cases does not exceed $$$10^5$$$;  The sum of $$$L$$$ over all test cases does not exceed $$$2\cdot 10^5$$$. OutputFor each test case, print "YES" if there exist at least three ways to choose the sets. Otherwise, print "NO".You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.ExampleInput63 22 1 21 11 24 103 1 2 32 4 51 64 7 8 9 102 54 1 2 3 44 1 2 3 45 55 1 2 3 4 55 1 2 3 4 55 1 2 3 4 55 1 2 3 4 55 1 2 3 4 55 104 1 2 3 45 1 2 5 6 75 2 6 7 8 94 6 7 8 92 9 105 51 11 21 32 4 51 5OutputYESNONOYESYESNONoteIn the first test case, there are $$$5\ge 3$$$ possible ways to choose the sets:   $$$S_1$$$ — both $$$1$$$ and $$$2$$$ are included in $$$S_1$$$;  $$$S_1$$$ and $$$S_2$$$ — $$$1$$$ is included in $$$S_1$$$ and $$$S_2$$$, and $$$2$$$ is included in $$$S_1$$$;  $$$S_1$$$ and $$$S_3$$$ — $$$1$$$ is included in $$$S_1$$$, and $$$2$$$ is included in $$$S_1$$$ and $$$S_3$$$;  $$$S_2$$$ and $$$S_3$$$ — $$$1$$$ is included in $$$S_2$$$, and $$$2$$$ is included in $$$S_3$$$;  $$$S_1$$$, $$$S_2$$$, and $$$S_3$$$ — $$$1$$$ is included in $$$S_1$$$ and $$$S_2$$$, and $$$2$$$ is included in $$$S_1$$$ and $$$S_3$$$. Note that it is invalid to choose $$$S_2$$$ only because $$$2$$$ is not included in $$$S_2$$$.In the second test case, the only way is to choose all the sets. In the third test case, $$$5$$$ does not appear in any of the sets, so there is no way to choose the sets.In the fourth test case, choosing any non-empty collection of the sets is valid, so the number of ways is $$$2^5-1=31\ge3$$$.