CF1773A.Amazing Trick
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice is a magician and she creates a new trick. She has n cards with different numbers from 1 to n written on them. First, she asks an audience member to shuffle the deck and put cards in a row. Let's say the i -th card from the left has the number ai on it.
Then Alice picks two permutations p and q . There is a restriction on p and q — permutations can't have fixed points. Which means ∀i:pi=i and qi=i .
After permutations are chosen, Alice shuffles the cards according to them. Now the i -th card from the left is the card a[p[q[i]] . The trick is considered successful if i -th card from the left has the number i on it after the shuffles.
Help Alice pick the permutations p and q or say it is not possible for the specific starting permutation a .
输入格式
The first line of the input contains the number of tests t ( 1≤t≤105 ).
Each test is described in two lines. The first line contains one integer n — the number of cards ( 1≤n≤105 ). The second line contains n integers ai — the initial permutation of the cards ( 1≤ai≤n ; ∀i=j:ai=aj ).
It is guaranteed that the sum of n over all tests does not exceed 105 .
输出格式
Print the answer for each test case in the same order the cases appear in the input.
For each test case, print "Impossible" in a single line, if no solution exists.
Otherwise, print "Possible" in the first line, and in the following two lines print permutations p and q .
输入输出样例
输入#1
4 2 2 1 3 1 2 3 4 2 1 4 3 5 5 1 4 2 3
输出#1
Impossible Possible 3 1 2 2 3 1 Possible 3 4 2 1 3 4 2 1 Possible 4 1 2 5 3 3 1 4 5 2