#P15137. [SWERC 2025] Chamber of Secrets 2
[SWERC 2025] Chamber of Secrets 2
题目描述
You are playing the game Henry Spotter and the Chamber of Secrets 2. You want to unlock the next level, the Chamber of Secrets. The entry door contains panels, each displaying a sequence of symbols. The product is even. The system generates these sequences from a secret permutation using the following four-step process:
- first, it starts from a secret permutation ;
- then, it repeats the secret permutation by concatenating it with itself, forming the array ;
- then, it splits this array into consecutive blocks, i.e., disjoint subarrays of length ;
- then, it shuffles these blocks in arbitrary order across the panels.
You are given the final panel sequences produced by the system. The -th panel shows . Your task is to recover one possible original secret permutation . For the given input, at least one solution exists. If multiple secret permutations are valid, output any one of them.
The concatenation of two arrays , is the array $[x_1, x_2, \dots, x_{k_1}, y_1, y_2, \dots, y_{k_2}]$ of length .
A permutation of length is an array consisting of distinct integers from 1 to in arbitrary order. For example, is a permutation, but is not a permutation (2 appears twice in the array), and is also not a permutation ( but there is 4 in the array).
输入格式
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers (, ) — the number of panels, and the length of each displayed sequence.
The -th of the next lines contains integers (), representing the sequence shown on the -th panel.
Note that there are no constraints on the sum of and over all test cases.
输出格式
For each test case, output a single line containing a secret permutation such that the process described above can produce the panel sequences . For the given input, at least one solution exists.
5
6 2
1 2
3 4
5 6
5 6
3 4
1 2
5 2
1 3
4 1
2 4
5 2
3 5
5 4
4 1 3 2
6 9 5 10
5 10 4 1
3 2 7 8
7 8 6 9
4 3
3 5 2
1 4 6
1 4 6
3 5 2
1 8
3 1 2 4 3 1 2 4
5 6 3 4 1 2
2 4 1 3 5
3 2 7 8 6 9 5 10 4 1
3 5 2 1 4 6
3 1 2 4
提示
Explanation of sample 1.
In the first test case, one valid secret permutation is :
- the array is the concatenation of two copies of ;
- splits into the blocks , , , , , ;
- after shuffling, the final panel sequences can coincide with these blocks.