CF2146B.Merging the Sets

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn sets S1,S2,…,SnS_1,S_2,\ldots,S_n, where each element in the sets is an integer between 11 and mm.

You want to choose some of the sets (possibly none or all), such that every integer between 11 and mm 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.

给你 nn 个集合 S1,S2,…,SnS_1, S_2, \ldots, S_n,其中每个集合中的元素均为 11 到 mm 之间的整数。

你需要从中选出若干个集合(可以一个都不选,也可以全部选择),使得 11 到 mm 之间的每个整数至少出现在所选集合中的一个里。

你需要判断:是否存在至少三种不同的选法。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (2≤n≤5⋅1042 \leq n \leq 5\cdot 10^4, 1≤m≤1051\le m \leq 10^5) — the number of sets and the upper bound of the integers in the sets.

Then nn lines follow, the ii-th line first containing an integer lil_i (1≤li≤m1\le l_i\le m) — the size of set SiS_i.

Then lil_i integers Si,1,Si,2,…,Si,liS_{i,1}, S_{i,2}, \ldots, S_{i, l_i} follow in the same line (1≤Si,1<Si,2<⋯<Si,li≤m1\le S_{i,1} \lt S_{i,2} \lt \cdots \lt S_{i, l_i}\le m) — the elements of set SiS_i.

Let L=∑i=1nliL=\sum\limits_{i=1}^n l_i. It is guaranteed that:

  • The sum of nn over all test cases does not exceed 5⋅1045\cdot 10^4;
  • The sum of mm over all test cases does not exceed 10510^5;
  • The sum of LL over all test cases does not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤5⋅1042 \leq n \leq 5\cdot 10^4,1≤m≤1051\le m \leq 10^5)——分别表示集合的数量以及集合中整数的上界。

接下来是 nn 行,其中第 ii 行首先包含一个整数 lil_i(1≤li≤m1\le l_i\le m)——表示集合 SiS_i 的大小。

随后在同一行给出 lil_i 个整数 Si,1,Si,2,…,Si,liS_{i,1}, S_{i,2}, \ldots, S_{i, l_i}(1≤Si,1<Si,2<⋯<Si,li≤m1\le S_{i,1} \lt S_{i,2} \lt \cdots \lt S_{i, l_i}\le m)——即集合 SiS_i 的元素。

令 L=∑i=1nliL=\sum\limits_{i=1}^n l_i。保证以下条件成立:

  • 所有测试用例中 nn 的总和不超过 5⋅1045\cdot 10^4;
  • 所有测试用例中 mm 的总和不超过 10510^5;
  • 所有测试用例中 LL 的总和不超过 2⋅1052\cdot 10^5。

输出格式

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≥35\ge 3 possible ways to choose the sets:

  • S1S_1 — both 11 and 22 are included in S1S_1;
  • S1S_1 and S2S_2 — 11 is included in S1S_1 and S2S_2, and 22 is included in S1S_1;
  • S1S_1 and S3S_3 — 11 is included in S1S_1, and 22 is included in S1S_1 and S3S_3;
  • S2S_2 and S3S_3 — 11 is included in S2S_2, and 22 is included in S3S_3;
  • S1S_1, S2S_2, and S3S_3 — 11 is included in S1S_1 and S2S_2, and 22 is included in S1S_1 and S3S_3.

Note that it is invalid to choose S2S_2 only because 22 is not included in S2S_2.

In the second test case, the only way is to choose all the sets.

In the third test case, 55 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≥32^5-1=31\ge3.

在第一个测试用例中,共有 5≥35\ge 3 种可能的方式选择集合:

  • 仅 S1S_1 — 11 和 22 均属于 S1S_1;
  • S1S_1 和 S2S_2 — 11 属于 S1S_1 和 S2S_2,且 22 属于 S1S_1;
  • S1S_1 和 S3S_3 — 11 属于 S1S_1,且 22 属于 S1S_1 和 S3S_3;
  • S2S_2 和 S3S_3 — 11 属于 S2S_2,且 22 属于 S3S_3;
  • S1S_1、S2S_2 和 S3S_3 — 11 属于 S1S_1 和 S2S_2,且 22 属于 S1S_1 和 S3S_3。

注意:仅选择 S2S_2 是无效的,因为 22 不在 S2S_2 中。

在第二个测试用例中,唯一可行的方式是选择所有集合。

在第三个测试用例中,55 不出现在任何一个集合中,因此不存在满足条件的集合选择方式。

在第四个测试用例中,任意非空的集合子集均有效,因此方案数为 25−1=31≥32^5-1=31\ge3。

输入解题思路,AI测评打分。不知道怎么写?

首页