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

26281번 - Amazing Trick 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB101252026.667%

문제

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 $a_i$ 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 $\forall i: p_i \ne i\ \text{and}\ q_i \ne 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ドル \leq t \leq 10^5$).

Each test is described in two lines. The first line contains one integer $n$ --- the number of cards (1ドル \leq n \leq 10^5$). The second line contains $n$ integers $a_i$ --- the initial permutation of the cards (1ドル \leq a_i \leq n$; $\forall i \neq j: a_i \neq a_j$).

It is guaranteed that the sum of $n$ over all tests does not exceed 10ドル^5$.

출력

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

힌트

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > Northern Eurasia Finals 2022 A번

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

출처

대학교 대회

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

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