CF2146B.Merging the Sets
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n sets S1,S2,…,Sn, 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.
给你 n 个集合 S1,S2,…,Sn,其中每个集合中的元素均为 1 到 m 之间的整数。
你需要从中选出若干个集合(可以一个都不选,也可以全部选择),使得 1 到 m 之间的每个整数至少出现在所选集合中的一个里。
你需要判断:是否存在至少三种不同的选法。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (2≤n≤5⋅104, 1≤m≤105) — 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 li (1≤li≤m) — the size of set Si.
Then li integers Si,1,Si,2,…,Si,li follow in the same line (1≤Si,1<Si,2<⋯<Si,li≤m) — the elements of set Si.
Let L=i=1∑nli. It is guaranteed that:
- The sum of n over all test cases does not exceed 5⋅104;
- The sum of m over all test cases does not exceed 105;
- The sum of L over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(2≤n≤5⋅104,1≤m≤105)——分别表示集合的数量以及集合中整数的上界。
接下来是 n 行,其中第 i 行首先包含一个整数 li(1≤li≤m)——表示集合 Si 的大小。
随后在同一行给出 li 个整数 Si,1,Si,2,…,Si,li(1≤Si,1<Si,2<⋯<Si,li≤m)——即集合 Si 的元素。
令 L=i=1∑nli。保证以下条件成立:
- 所有测试用例中 n 的总和不超过 5⋅104;
- 所有测试用例中 m 的总和不超过 105;
- 所有测试用例中 L 的总和不超过 2⋅105。
输出格式
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.
对于每个测试用例,如果存在至少三种选择这些集合的方式,则输出 "YES";否则输出 "NO"。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。
输入输出样例
输入#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
输出#1
YES NO NO YES YES NO
说明/提示
In the first test case, there are 5≥3 possible ways to choose the sets:
- S1 — both 1 and 2 are included in S1;
- S1 and S2 — 1 is included in S1 and S2, and 2 is included in S1;
- S1 and S3 — 1 is included in S1, and 2 is included in S1 and S3;
- S2 and S3 — 1 is included in S2, and 2 is included in S3;
- S1, S2, and S3 — 1 is included in S1 and S2, and 2 is included in S1 and S3.
Note that it is invalid to choose S2 only because 2 is not included in S2.
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 25−1=31≥3.
在第一个测试用例中,共有 5≥3 种可能的方式选择集合:
- 仅 S1 — 1 和 2 均属于 S1;
- S1 和 S2 — 1 属于 S1 和 S2,且 2 属于 S1;
- S1 和 S3 — 1 属于 S1,且 2 属于 S1 和 S3;
- S2 和 S3 — 1 属于 S2,且 2 属于 S3;
- S1、S2 和 S3 — 1 属于 S1 和 S2,且 2 属于 S1 和 S3。
注意:仅选择 S2 是无效的,因为 2 不在 S2 中。
在第二个测试用例中,唯一可行的方式是选择所有集合。
在第三个测试用例中,5 不出现在任何一个集合中,因此不存在满足条件的集合选择方式。
在第四个测试用例中,任意非空的集合子集均有效,因此方案数为 25−1=31≥3。
输入解题思路,AI测评打分。不知道怎么写?