Ambiguous Permutations

시간 제한2초메모리 제한1024 MB

요약
두 순열에서 상대 순서가 같아야 하는 인덱스 쌍들이 주어질 때, 모든 제약을 만족하는 서로 다른 두 순열을 찾거나 불가능함을 판별한다.
난이도

어려움10점 중 8점

유형
그래프, 그리디, 정렬, 구현
정답자
아직 제출이 없습니다

문제

You want to find two permutations pp and qq of size nn that satisfy mm restrictions of the form (p_i−p_j)⋅(q_i−q_j)>0(p\_i-p\_j)\cdot (q\_i-q\_j)>0.

A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, \[2,3,1,5,4]\[2, 3, 1, 5, 4] is a permutation, but \[1,2,2]\[1, 2, 2] is not a permutation (22 appears twice in the array), and \[1,3,4]\[1, 3, 4] is also not a permutation (l=3l=3 but there is 44 in the array).

Find two distinct permutations pp and qq of size nn such that all restrictions are satisfied, or state that it is impossible to do so. pp and qq are considered distinct if there is at least one index ii where p_i≠q_ip\_i \neq q\_i.

입력

The first line of the input contains a single integer tt (1≤t≤1041\le t\le 10^4) --- the number of test cases.

The first line of each test case contains two integers nn and mm (1≤n≤2⋅1051\leq n\leq 2\cdot 10^5, 0≤m≤min(2⋅105,n(n−1)2)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 mm lines of the test case contains two integers ii and jj (1≤i<j≤n1 \le i < j \le n) --- representing the restriction (p_i−p_j)⋅(q_i−q_j)>0(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 nn over all test cases does not exceed 2⋅1052\cdot 10^5.

Similarly, the sum of mm over all test cases does not exceed 2⋅1052\cdot 10^5.

출력

The first line of output for each test case should contain "YES" if a valid pp and qq 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 nn distinct integers p_1,,p_2,⋯,p_np\_1,\\, p\_2, \cdots\\, p\_n (1≤p_i≤n1 \le p\_i \le n) --- the permutation pp.

The second of these should contain nn distinct integers q_1,,q_2,,⋯,q_nq\_1,\\, q\_2,\\, \cdots\\, q\_n (1≤q_i≤n1 \le q\_i \le n) --- the permutation qq.

힌트

In the first test case of the first test, n=1n=1. Since there is only one distinct permutation of size 11, there is no solution.

In the second test case of the first test, n=2n=2 and there are no restrictions that need to be satisfied. So p=\[1,,2]p = \[1,\\, 2] and q=\[2,,1]q = \[2,\\,1] is a valid solution.

예제3

  1. 예제 1

    입력
    3
    1 0
    2 0
    2 1
    1 2
    
    예상 출력
    No
    Yes
    1 2 
    2 1 
    No
    
  2. 예제 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
    
    예상 출력
    Yes
    5 3 4 1 2
    4 3 5 1 2
    Yes
    1 3 4 2
    1 2 3 4
    
  3. 예제 3

    입력
    1
    5 10
    1 2
    1 3
    1 4
    1 5
    2 3
    2 4
    2 5
    3 4
    3 5
    4 5
    
    예상 출력
    No