#P1015. Merging the Sets —— 合并集合
Merging the Sets —— 合并集合
Statement
You are given sets , where each element in the sets is an integer between and .
You want to choose some of the sets (possibly none or all), such that every integer between and 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
The first line of each test case contains two integers and (, ) — the number of sets and the upper bound of the integers in the sets.
Then lines follow, the -th line first containing an integer () — the size of set .
Then integers follow in the same line ($1\leqslant S_{i,1} < S_{i,2} < \cdots < S_{i, \ell_i}\leqslant m$) — the elements of set .
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.
Samples
3 2
2 1 2
1 1
1 2
YES
4 10
3 1 2 3
2 4 5
1 6
4 7 8 9 10
NO
2 5
4 1 2 3 4
4 1 2 3 4
NO
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
YES
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
YES
5 5
1 1
1 2
1 3
2 4 5
1 5
NO
Note
In the first test case, there are possible ways to choose the sets:
- — both and are included in ;
- and — is included in and , and is included in ;
- and — is included in , and is included in and ;
- and — is included in , and is included in ;
- , , and — is included in and , and is included in and .
Note that it is invalid to choose only because is not included in .
In the second test case, the only way is to choose all the sets.
In the third test case, 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 .
相關
在下列比赛中: