Logo
(追記) (追記ここまで)

32743번 - Ambiguous Permutations 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB318833.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$.

제한

예제 입력 1

3
1 0
2 0
2 1
1 2

예제 출력 1

No
Yes
1 2 
2 1 
No

예제 입력 2

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

예제 출력 2

Yes
5 3 4 1 2
4 3 5 1 2
Yes
1 3 4 2
1 2 3 4

예제 입력 3

1
5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

예제 출력 3

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.

출처

University > Rutgers University > Rutgers Programming Contest Fall 2024 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /