Ambiguous Permutations
시간 제한2초메모리 제한1024 MB
두 순열에서 상대 순서가 같아야 하는 인덱스 쌍들이 주어질 때, 모든 제약을 만족하는 서로 다른 두 순열을 찾거나 불가능함을 판별한다.
문제
You want to find two permutations and of size that satisfy restrictions of the form .
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
Find two distinct permutations and of size such that all restrictions are satisfied, or state that it is impossible to do so. and are considered distinct if there is at least one index where .
입력
The first line of the input contains a single integer () --- the number of test cases.
The first line of each test case contains two integers and (, ) --- the size of the permutations and the number of restrictions, respectively.
Each of the next lines of the test case contains two integers and () --- representing the restriction . It is guaranteed that all restrictions in the input are distinct.
It is guaranteed that the sum of over all test cases does not exceed .
Similarly, the sum of over all test cases does not exceed .
출력
The first line of output for each test case should contain "YES" if a valid and 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 distinct integers () --- the permutation .
The second of these should contain distinct integers () --- the permutation .
힌트
In the first test case of the first test, . Since there is only one distinct permutation of size , there is no solution.
In the second test case of the first test, and there are no restrictions that need to be satisfied. So and is a valid solution.