| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 31 | 8 | 8 | 33.333% |
You want to find two permutations $p$ and $q$ of size $n$ that satisfy $m$ restrictions of the form $(p_i-p_j)\cdot (q_i-q_j)>0$.
A permutation of length $n$ is an array consisting of $n$ distinct integers from 1ドル$ to $n$ in arbitrary order. For example, $[2, 3, 1, 5, 4]$ is a permutation, but $[1, 2, 2]$ is not a permutation (2ドル$ appears twice in the array), and $[1, 3, 4]$ is also not a permutation ($l=3$ but there is 4ドル$ in the array).
Find two distinct permutations $p$ and $q$ of size $n$ such that all restrictions are satisfied, or state that it is impossible to do so. $p$ and $q$ are considered distinct if there is at least one index $i$ where $p_i \neq q_i$.
The first line of the input contains a single integer $t$ (1ドル\le t\le 10^4$) --- the number of test cases.
The first line of each test case contains two integers $n$ and $m$ (1ドル\leq n\leq 2\cdot 10^5,ドル 0ドル \le m \le min(2\cdot 10^5, \frac{n(n-1)}{2})$) --- the size of the permutations and the number of restrictions, respectively.
Each of the next $m$ lines of the test case contains two integers $i$ and $j$ (1ドル \le i < j \le n$) --- representing the restriction $(p_i-p_j)\cdot (q_i-q_j)>0$. It is guaranteed that all restrictions in the input are distinct.
It is guaranteed that the sum of $n$ over all test cases does not exceed 2ドル\cdot 10^5$.
Similarly, the sum of $m$ over all test cases does not exceed 2ドル\cdot 10^5$.
The first line of output for each test case should contain "YES" if a valid $p$ and $q$ exist, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
If you printed "YES", print two additional lines of output.
The first of these should contain $n$ distinct integers $p_1,,円 p_2, \cdots,円 p_n$ (1ドル \le p_i \le n$) --- the permutation $p$.
The second of these should contain $n$ distinct integers $q_1,,円 q_2,,円 \cdots,円 q_n$ (1ドル \le q_i \le n$) --- the permutation $q$.
3 1 0 2 0 2 1 1 2
No Yes 1 2 2 1 No
2 5 8 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 4 3 1 2 1 3 1 4
Yes 5 3 4 1 2 4 3 5 1 2 Yes 1 3 4 2 1 2 3 4
1 5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5
No
In the first test case of the first test, $n=1$. Since there is only one distinct permutation of size 1ドル,ドル there is no solution.
In the second test case of the first test, $n=2$ and there are no restrictions that need to be satisfied. So $p = [1,,円 2]$ and $q = [2,,1円]$ is a valid solution.