Permutation Recovery
시간 제한2초메모리 제한2048 MB
크기 n인 숨은 순열 a와 b에 대해 a(b_i)와 b(a_i) 값이 주어질 때, 조건을 만족하는 a와 b를 복원하거나 존재하지 않음을 판정한다.
문제
There are two hidden permutations and of size .
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).
For each from to , you are given the values and . Recover any possible permutations and , or determine that none exist.
입력
The first line of the input contains a single integer () --- the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () --- the size of the two permutations.
The second line of each test case contains integers. The -th of these is (). It is guaranteed that these integers are distinct.
The third line of each test case contains integers. The -th of these is (). It is guaranteed that these integers are distinct.
It is guaranteed that the sum of across all test cases is at most .
출력
For each test case, the first line of output should contain "YES" if there is a solution, and "NO" otherwise.
If you print "YES", print two additional lines of output:
The first line should contain integers () --- a valid permutation .
The second line should contain integers () --- a valid permutation .
If there are multiple solutions, you may print any.
힌트
The given solution to the first sample case is , . This gives which matches the input values and .
In the second sample case, it can be shown that there are no valid permutations and .