#P13956. [ICPC 2023 Nanjing R] 等价重写

    ID: 13904 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论2023Special Judge拓扑排序ICPC南京

[ICPC 2023 Nanjing R] 等价重写

Description

There is a sequence AA of length mm where all elements equal to 00. We will then execute nn operations on AA in order. The ii-th operation can be denoted as pip_i distinct integers bi,1,bi,2,,bi,pib_{i, 1}, b_{i, 2}, \cdots, b_{i, p_i}, indicating that we'll change the value of the bi,jb_{i, j}-th element in the sequence to ii for all 1jpi1 \le j \le p_i. Let RR be the resulting sequence after all operations.

We now require you to rearrange the operations but still produce the same result. More formally, let q1,q2,,qnq_1, q_2, \cdots, q_n be a permutation of nn that differs from 1,2,,n1, 2, \cdots, n. You'll execute the q1q_1-th, q2q_2-th, ..., qnq_n-th operation on sequence AA in order, and the final resulting sequence must equal to RR. Your task is to find such permutation or state that it does not exist.

Recall that a permutation of nn is a sequence of length nn in which each integer from 11 to nn (both inclusive) appears exactly once. Let x1,x2,,xnx_1, x_2, \cdots, x_n and y1,y2,,yny_1, y_2, \cdots, y_n be two permutations of nn. We say they're different if there exists an integer kk such that 1kn1 \le k \le n and xkykx_k \ne y_k.

Input Format

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (1n,m1051 \leq n, m \leq 10^5) indicating the number of operations and the length of the sequence.

For the following nn lines, the ii-th line first contains an integer pip_i (1pim1 \le p_i \le m) indicating the number of elements changed by the ii-th operation. Then pip_i distinct integers bi,1,bi,2,,bi,pib_{i,1}, b_{i,2}, \cdots, b_{i,p_i} follow (1bi,jm1 \le b_{i,j} \le m) indicating the index of the elements to be changed.

It is guaranteed that the sum of (n+m)(n + m) of all test cases will not exceed 2×1062 \times 10^6, and the sum of pip_i of all test cases will not exceed 10610^6.

Output Format

For each test case, if such permutation exists, first output Yes\texttt{Yes} in one line. Then output nn integers q1,q2,,qnq_1, q_2, \cdots, q_n 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 No\texttt{No} 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 {1,2,3}\{1, 2, 3\} or {3,1,2}\{3, 1, 2\} yields the same resulting sequence {1,3,2,0,2,3}\{1, 3, 2, 0, 2, 3\}.