CF1798B.Three Sevens
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Lottery "Three Sevens" was held for m days. On day i, ni people with the numbers ai,1,…,ai,ni participated in the lottery.
It is known that in each of the m days, only one winner was selected from the lottery participants. The lottery winner on day i was not allowed to participate in the lottery in the days from i+1 to m.
Unfortunately, the information about the lottery winners has been lost. You need to find any possible list of lottery winners on days from 1 to m or determine that no solution exists.
“三个七”彩票活动共举行了 m 天。在第 i 天,有 ni 人参与抽奖,他们的号码分别为 ai,1,…,ai,ni。
已知在全部 m 天中,每天恰好从当天的参与者中选出一名中奖者。且第 i 天的中奖者不得再参加第 i+1 天至第 m 天的抽奖。
不幸的是,有关各日中奖者的信息已全部丢失。你需要找出一个可能的、从第 1 天到第 m 天的中奖者序列;若不存在满足条件的序列,则判定无解。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤50000). The description of the test cases follows.
The first line of each test case contains a single integer m (1≤m≤50000) — the number of days in which the lottery was held.
Next, for each i from 1 to m, follows a two-line block of data.
The first line of each block contains a single integer ni (1≤ni≤50000) — the number of lottery participants on day i.
The second line of the block contains integers ai,1,…,ai,ni (1≤ai,j≤50000) — lottery participants on day i. It is guaranteed that all the numbers ai,1,…,ai,ni are pairwise distinct.
It is guaranteed that the sum of ni over all blocks of all test cases does not exceed 50000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤50000)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 m(1≤m≤50000)—— 表示彩票举办的天数。
接下来,对每个 i(从 1 到 m),给出一个两行的数据块。
每个数据块的第一行包含一个整数 ni(1≤ni≤50000)—— 表示第 i 天的彩票参与者人数。
该数据块的第二行包含整数 ai,1,…,ai,ni(1≤ai,j≤50000)—— 表示第 i 天的彩票参与者。保证所有数字 ai,1,…,ai,ni 两两互异。
保证所有测试用例中所有数据块的 ni 之和不超过 50000。
输出格式
For each test case, if there is no solution, print a single integer −1.
Otherwise, print m integers p1,p2,…,pm (1≤pi≤50000) — lottery winners on days from 1 to m. If there are multiple solutions, print any of them.
对于每个测试用例,若无解,则输出单个整数 −1。
否则,输出 m 个整数 p1,p2,…,pm(1≤pi≤50000),表示第 1 天到第 m 天的彩票中奖者。若存在多个解,输出任意一个即可。
输入输出样例
输入#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] since the participant with the number 8 participated on day 1, but did not participate on days 2 and 3; the participant with the number 2 participated on day 2, but did not participate on day 3; and the participant with the number 1 participated on day 3. Note that this is not the only possible answer, for example, [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 1 must have participated on the day 2, which is not allowed. Thus, there is no correct answer.
In the third test case, only one participant participated on days 2, 3, 4, and on day 1 there is only one participant who did not participate in the lottery on days 2,3,4 — participant 2, which means [2,1,4,3] is the only correct answer to this test case.
在第一个测试用例中,一个可能的答案是 [8,2,1],因为编号为 8 的参与者仅在第 1 天参与,而在第 2 天和第 3 天均未参与;编号为 2 的参与者仅在第 2 天参与,而在第 3 天未参与;编号为 1 的参与者在第 3 天参与。注意,这并非唯一可能的答案,例如 [8,9,4] 同样是一个正确答案。
在第二个测试用例中,两名抽奖参与者均在第 1 天和第 2 天都参与了抽奖,因此第 1 天的任何可能中奖者都必然也在第 2 天参与了抽奖,而这违反了题目要求。因此,该测试用例不存在正确答案。
在第三个测试用例中,仅有唯一一名参与者在第 2、3、4 天均参与了抽奖;而在第 1 天,仅有一名参与者未在第 2、3、4 天参与抽奖——即参与者 2。这意味着 [2,1,4,3] 是该测试用例的唯一正确答案。
输入解题思路,AI测评打分。不知道怎么写?