Codeforces Round 1052 (Div. 2)
B
Merging the Sets
Codeforces
1100
原题
← AC →
翻译中…

You 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.

翻译中…

Input

翻译中…

Each 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} \lt S_{i,2} \lt \cdots \lt 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$.
翻译中…

Output

翻译中…

For 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.

翻译中…

Note

翻译中…

In 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$.

翻译中…

样例

Input #1
6
3 2
2 1 2
1 1
1 2
4 10
3 1 2 3
2 4 5
1 6
4 7 8 9 10
2 5
4 1 2 3 4
4 1 2 3 4
5 5
5 1 2 3 4 5
5 1 2 3 4 5
5 1 2 3 4 5
5 1 2 3 4 5
5 1 2 3 4 5
5 10
4 1 2 3 4
5 1 2 5 6 7
5 2 6 7 8 9
4 6 7 8 9
2 9 10
5 5
1 1
1 2
1 3
2 4 5
1 5
Output #1
YES
NO
NO
YES
YES
NO
InputCopy OutputCopy
题目信息
题号
2146B
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。