CF1798B.Three Sevens

普及/提高-

通过率:0%

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.

输入格式

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

The first line of each test case contains a single integer mm ( 1m500001 \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 ( 1ni500001 \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} ( 1ai,j500001 \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 5000050\,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 ( 1pi500001 \le p_i \le 50\,000 ) — lottery winners on days from 11 to mm . If there are multiple solutions, print any of them.

输入输出样例

  • 输入#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.

首页