CF1798B.Three Sevens

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Lottery "Three Sevens" was held for mm days. On day ii, nin_i people with the numbers ai,1,…,ai,nia_{i, 1}, \ldots, a_{i, n_i} participated in the lottery.

It is known that in each of the mm days, only one winner was selected from the lottery participants. The lottery winner on day ii was not allowed to participate in the lottery in the days from i+1i+1 to mm.

Unfortunately, the information about the lottery winners has been lost. You need to find any possible list of lottery winners on days from 11 to mm or determine that no solution exists.

“三个七”彩票活动共举行了 mm 天。在第 ii 天,有 nin_i 人参与抽奖,他们的号码分别为 ai,1,…,ai,nia_{i, 1}, \ldots, a_{i, n_i}。

已知在全部 mm 天中,每天恰好从当天的参与者中选出一名中奖者。且第 ii 天的中奖者不得再参加第 i+1i+1 天至第 mm 天的抽奖。

不幸的是,有关各日中奖者的信息已全部丢失。你需要找出一个可能的、从第 11 天到第 mm 天的中奖者序列;若不存在满足条件的序列,则判定无解。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤50 0001 \le t \le 50\,000). The description of the test cases follows.

The first line of each test case contains a single integer mm (1≤m≤50 0001 \le m \le 50\,000) — the number of days in which the lottery was held.

Next, for each ii from 11 to mm, follows a two-line block of data.

The first line of each block contains a single integer nin_i (1≤ni≤50 0001 \le n_i \le 50\,000) — the number of lottery participants on day ii.

The second line of the block contains integers ai,1,…,ai,nia_{i, 1}, \ldots, a_{i, n_i} (1≤ai,j≤50 0001 \le a_{i, j} \le 50\,000) — lottery participants on day ii. It is guaranteed that all the numbers ai,1,…,ai,nia_{i, 1}, \ldots, a_{i, n_i} are pairwise distinct.

It is guaranteed that the sum of nin_i over all blocks of all test cases does not exceed 50 00050\,000.

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

每个测试用例的第一行包含一个整数 mm(1≤m≤50 0001 \le m \le 50\,000)—— 表示彩票举办的天数。

接下来,对每个 ii(从 11 到 mm),给出一个两行的数据块。

每个数据块的第一行包含一个整数 nin_i(1≤ni≤50 0001 \le n_i \le 50\,000)—— 表示第 ii 天的彩票参与者人数。

该数据块的第二行包含整数 ai,1,…,ai,nia_{i, 1}, \ldots, a_{i, n_i}(1≤ai,j≤50 0001 \le a_{i, j} \le 50\,000)—— 表示第 ii 天的彩票参与者。保证所有数字 ai,1,…,ai,nia_{i, 1}, \ldots, a_{i, n_i} 两两互异。

保证所有测试用例中所有数据块的 nin_i 之和不超过 50 00050\,000。

输出格式

For each test case, if there is no solution, print a single integer −1-1.

Otherwise, print mm integers p1,p2,…,pmp_1, p_2, \ldots, p_m (1≤pi≤50 0001 \le p_i \le 50\,000) — lottery winners on days from 11 to mm. If there are multiple solutions, print any of them.

对于每个测试用例,若无解,则输出单个整数 −1-1。

否则,输出 mm 个整数 p1,p2,…,pmp_1, p_2, \ldots, p_m(1≤pi≤50 0001 \le p_i \le 50\,000),表示第 11 天到第 mm 天的彩票中奖者。若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    3
    4
    1 2 4 8
    3
    2 9 1
    2
    1 4
    2
    2
    1 2
    2
    2 1
    4
    4
    1 2 3 4
    1
    1
    1
    4
    1
    3

    输出#1

    8 2 1 
    -1
    2 1 4 3

说明/提示

In the first test case, one of the answers is [8,2,1][8, 2, 1] since the participant with the number 88 participated on day 11, but did not participate on days 22 and 33; the participant with the number 22 participated on day 22, but did not participate on day 33; and the participant with the number 11 participated on day 33. Note that this is not the only possible answer, for example, [8,9,4][8, 9, 4] is also a correct answer.

In the second test case, both lottery participants participated on both days, so any possible lottery winner on the day 11 must have participated on the day 22, which is not allowed. Thus, there is no correct answer.

In the third test case, only one participant participated on days 22, 33, 44, and on day 11 there is only one participant who did not participate in the lottery on days 2,3,42, 3, 4 — participant 22, which means [2,1,4,3][2, 1, 4, 3] is the only correct answer to this test case.

在第一个测试用例中,一个可能的答案是 [8,2,1][8, 2, 1],因为编号为 88 的参与者仅在第 11 天参与,而在第 22 天和第 33 天均未参与;编号为 22 的参与者仅在第 22 天参与,而在第 33 天未参与;编号为 11 的参与者在第 33 天参与。注意,这并非唯一可能的答案,例如 [8,9,4][8, 9, 4] 同样是一个正确答案。

在第二个测试用例中,两名抽奖参与者均在第 11 天和第 22 天都参与了抽奖,因此第 11 天的任何可能中奖者都必然也在第 22 天参与了抽奖,而这违反了题目要求。因此,该测试用例不存在正确答案。

在第三个测试用例中,仅有唯一一名参与者在第 22、33、44 天均参与了抽奖;而在第 11 天,仅有一名参与者未在第 22、33、44 天参与抽奖——即参与者 22。这意味着 [2,1,4,3][2, 1, 4, 3] 是该测试用例的唯一正确答案。

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

首页