#P13956. [ICPC 2023 Nanjing R] 等价重写
[ICPC 2023 Nanjing R] 等价重写
Description
There is a sequence of length where all elements equal to . We will then execute operations on in order. The -th operation can be denoted as distinct integers , indicating that we'll change the value of the -th element in the sequence to for all . Let be the resulting sequence after all operations.
We now require you to rearrange the operations but still produce the same result. More formally, let be a permutation of that differs from . You'll execute the -th, -th, ..., -th operation on sequence in order, and the final resulting sequence must equal to . Your task is to find such permutation or state that it does not exist.
Recall that a permutation of is a sequence of length in which each integer from to (both inclusive) appears exactly once. Let and be two permutations of . We say they're different if there exists an integer such that and .
Input Format
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains two integers and () indicating the number of operations and the length of the sequence.
For the following lines, the -th line first contains an integer () indicating the number of elements changed by the -th operation. Then distinct integers follow () indicating the index of the elements to be changed.
It is guaranteed that the sum of of all test cases will not exceed , and the sum of of all test cases will not exceed .
Output Format
For each test case, if such permutation exists, first output in one line. Then output integers separated by a space in the second line indicating the answer. If there are multiple valid answers, you can output any of them.
If there is no such permutation, simply output in one line.
Please, DO NOT output extra spaces at the end of each line, or your solution may be considered incorrect!
3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1
Yes
3 1 2
No
No
Hint
For the first sample test case, by executing the operations in either order of or yields the same resulting sequence .
京公网安备 11011102002149号