CF1882B.Sets and Union

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have nn sets of integers S1,S2,…,SnS_{1}, S_{2}, \ldots, S_{n}. We call a set SS attainable, if it is possible to choose some (possibly, none) of the sets S1,S2,…,SnS_{1}, S_{2}, \ldots, S_{n} so that SS is equal to their union†^{\dagger}. If you choose none of S1,S2,…,SnS_{1}, S_{2}, \ldots, S_{n}, their union is an empty set.

Find the maximum number of elements in an attainable SS such that S≠S1∪S2∪…∪SnS \neq S_{1} \cup S_{2} \cup \ldots \cup S_{n}.

†^{\dagger} The union of sets A1,A2,…,AkA_1, A_2, \ldots, A_k is defined as the set of elements present in at least one of these sets. It is denoted by A1∪A2∪…∪AkA_1 \cup A_2 \cup \ldots \cup A_k. For example, 2,4,6∪2,3∪3,6,7=2,3,4,6,7{2, 4, 6} \cup {2, 3} \cup {3, 6, 7} = {2, 3, 4, 6, 7}.

你有 nn 个整数集合 S1,S2,…,SnS_{1}, S_{2}, \ldots, S_{n}。我们称一个集合 SS 是可达成的(attainable),如果能够从 S1,S2,…,SnS_{1}, S_{2}, \ldots, S_{n} 中选出若干个(可能一个也不选),使得 SS 恰好等于这些被选出集合的并集†^{\dagger}。若一个集合都不选,则它们的并集为空集。

求所有满足 S≠S1∪S2∪…∪SnS \neq S_{1} \cup S_{2} \cup \ldots \cup S_{n} 的可达成集合 SS 中,元素个数的最大值。

†^{\dagger} 集合 A1,A2,…,AkA_1, A_2, \ldots, A_k 的并集定义为至少属于其中某一个集合的所有元素构成的集合,记作 A1∪A2∪…∪AkA_1 \cup A_2 \cup \ldots \cup A_k。例如,2,4,6∪2,3∪3,6,7=2,3,4,6,7{2, 4, 6} \cup {2, 3} \cup {3, 6, 7} = {2, 3, 4, 6, 7}。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤501 \le n \le 50).

The following nn lines describe the sets S1,S2,…,SnS_1, S_2, \ldots, S_n. The ii-th of these lines contains an integer kik_{i} (1≤ki≤501 \le k_{i} \le 50) — the number of elements in SiS_{i}, followed by kik_{i} integers si,1,si,2,…,si,kis_{i, 1}, s_{i, 2}, \ldots, s_{i, k_{i}} (1≤si,1<si,2<…<si,ki≤501 \le s_{i, 1} \lt s_{i, 2} \lt \ldots \lt s_{i, k_{i}} \le 50) — the elements of SiS_{i}.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤501 \le n \le 50)。

接下来的 nn 行描述集合 S1,S2,…,SnS_1, S_2, \ldots, S_n。其中第 ii 行包含一个整数 kik_{i}(1≤ki≤501 \le k_{i} \le 50)——表示集合 SiS_{i} 中元素的个数,随后是 kik_{i} 个整数 si,1,si,2,…,si,kis_{i, 1}, s_{i, 2}, \ldots, s_{i, k_{i}}(1≤si,1<si,2<…<si,ki≤501 \le s_{i, 1} \lt s_{i, 2} \lt \ldots \lt s_{i, k_{i}} \le 50)——即集合 SiS_{i} 的所有元素。

输出格式

For each test case, print a single integer — the maximum number of elements in an attainable SS such that S≠S1∪S2∪…∪SnS \neq S_{1} \cup S_{2} \cup \ldots \cup S_{n}.

对于每个测试用例,输出一个整数——即可达到的集合 SS 的最大元素个数,满足 S≠S1∪S2∪…∪SnS \neq S_{1} \cup S_{2} \cup \ldots \cup S_{n}。

输入输出样例

  • 输入#1

    4
    3
    3 1 2 3
    2 4 5
    2 3 4
    4
    4 1 2 3 4
    3 2 5 6
    3 3 5 6
    3 4 5 6
    5
    1 1
    3 3 6 10
    1 9
    2 1 3
    3 5 8 9
    1
    2 4 28

    输出#1

    4
    5
    6
    0

说明/提示

In the first test case, S=S1∪S3=1,2,3,4S = S_{1} \cup S_{3} = {1, 2, 3, 4} is the largest attainable set not equal to S1∪S2∪S3=1,2,3,4,5S_1 \cup S_2 \cup S_3 = {1, 2, 3, 4, 5}.

In the second test case, we can pick S=S2∪S3∪S4=2,3,4,5,6S = S_{2} \cup S_{3} \cup S_{4} = {2, 3, 4, 5, 6}.

In the third test case, we can pick S=S2∪S5=S2∪S3∪S5=3,5,6,8,9,10S = S_{2} \cup S_{5} = S_{2} \cup S_{3} \cup S_{5} = {3, 5, 6, 8, 9, 10}.

In the fourth test case, the only attainable set is S=∅S = \varnothing.

在第一个测试用例中,S=S1∪S3=1,2,3,4S = S_{1} \cup S_{3} = {1, 2, 3, 4} 是可达到的最大集合,且不等于 S1∪S2∪S3=1,2,3,4,5S_1 \cup S_2 \cup S_3 = {1, 2, 3, 4, 5}。

在第二个测试用例中,我们可以选取 S=S2∪S3∪S4=2,3,4,5,6S = S_{2} \cup S_{3} \cup S_{4} = {2, 3, 4, 5, 6}。

在第三个测试用例中,我们可以选取 S=S2∪S5=S2∪S3∪S5=3,5,6,8,9,10S = S_{2} \cup S_{5} = S_{2} \cup S_{3} \cup S_{5} = {3, 5, 6, 8, 9, 10}。

在第四个测试用例中,唯一可达到的集合是 S=∅S = \varnothing。

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

首页