CF1790C.Premutation
入门
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A sequence of n numbers is called permutation if it contains all integers from 1 to n exactly once. For example, the sequences [3,1,4,2], [1] and [2,1] are permutations, but [1,2,1], [0,1] and [1,3,4] — are not.
Kristina had a permutation p of n elements. She wrote it on the whiteboard n times in such a way that:
- while writing the permutation at the i-th (1≤i≤n) time she skipped the element pi
So, she wrote in total n sequences of length n−1 each.
For example, suppose Kristina had a permutation p = [4,2,1,3] of length 4. Then she did the following:
- Wrote the sequence [2,1,3], skipping the element p1=4 from the original permutation.
- Wrote the sequence [4,1,3], skipping the element p2=2 from the original permutation.
- Wrote the sequence [4,2,3], skipping the element p3=1 from the original permutation.
- Wrote the sequence [4,2,1], skipping the element p4=3 from the original permutation.
You know all n of sequences that have been written on the whiteboard, but you do not know the order in which they were written. They are given in arbitrary order. Reconstruct the original permutation from them.
For example, if you know the sequences [4,2,1], [4,2,3], [2,1,3], [4,1,3], then the original permutation will be p = [4,2,1,3].
一个包含 n 个数的序列被称为排列,当且仅当它恰好包含从 1 到 n 的所有整数各一次。例如,序列 [3,1,4,2]、[1] 和 [2,1] 是排列,但 [1,2,1]、[0,1] 和 [1,3,4] 不是。
克里斯蒂娜有一个长度为 n 的排列 p。她将该排列在黑板上写了 n 遍,写法如下:
- 在第 i 次(其中 1≤i≤n)书写时,她跳过了原排列中的元素 pi。
因此,她总共写下了 n 个长度均为 n−1 的序列。
例如,假设克里斯蒂娜的排列 p=[4,2,1,3],长度为 4,则她的操作如下:
- 跳过原排列中第 1 个元素 p1=4,写下序列 [2,1,3];
- 跳过原排列中第 2 个元素 p2=2,写下序列 [4,1,3];
- 跳过原排列中第 3 个元素 p3=1,写下序列 [4,2,3];
- 跳过原排列中第 4 个元素 p4=3,写下序列 [4,2,1]。
你已知黑板上所写的全部 n 个序列,但不知道它们被书写的顺序——这些序列以任意顺序给出。请根据这些序列重构出原始排列。
例如,若你已知的序列为 [4,2,1]、[4,2,3]、[2,1,3]、[4,1,3],则原始排列为 p=[4,2,1,3]。
输入格式
The first line of input data contains a single integer t (1≤t≤104) — the number of test cases.
The description of the test cases follows.
The first line of each test case contains one integer n (3≤n≤100).
This is followed by n lines, each containing exactly n−1 integers and describing one of the sequences written out on the whiteboard.
It is guaranteed that all sequences could be obtained from some permutation p, and that the sum n2 over all input sets does not exceed 2⋅105.
输入数据的第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
接下来是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(3≤n≤100)。
随后是 n 行,每行恰好包含 n−1 个整数,描述白板上写出的一个序列。
保证所有序列均可由某个排列 p 得到,且所有输入数据集中 n2 的总和不超过 2⋅105。
输出格式
For each test case, output on a separate line a permutation p such that the given n sequences could be obtained from it.
It is guaranteed that the answer exists and it is the only one. In other words, for each test case the required permutation is sure to exist.
对于每个测试用例,在单独一行输出一个排列 p,使得给定的 n 个序列均可由该排列得到。
保证答案存在且唯一。换言之,对每个测试用例,所要求的排列一定存在。
输入输出样例
输入#1
5 4 4 2 1 4 2 3 2 1 3 4 1 3 3 2 3 1 3 1 2 5 4 2 1 3 2 1 3 5 4 2 3 5 4 1 3 5 4 2 1 5 4 2 3 4 1 3 4 1 2 3 1 2 4 3 2 1 1 3 2 3
输出#1
4 2 1 3 1 2 3 4 2 1 3 5 1 2 3 4 2 1 3
说明/提示
The first test case is described in the problem statement.
In the second test case, the sequences are written in the correct order.
第一个测试用例在题目描述中已给出。
在第二个测试用例中,序列按正确顺序书写。
输入解题思路,AI测评打分。不知道怎么写?