#686
Gold V
Farmer John's Favorite Permutation
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John has a permutation pp of length NN (2N105)2 \leq N \leq 10^5), containing each positive integer from 11 to NN exactly once. However, Farmer Nhoj has broken into FJ's barn and disassembled pp. To not be too cruel, FN has written some hints that will help FJ reconstruct pp. While there is more than one element remaining in pp, FN does the following:

Let the remaining elements of pp be p1,p2,,pnp'_1, p'_2, \dots , p'_n, If p1>pnp'_1 > p'_n, he writes down p2p'_2 and removes p1p'_1 from the permutation. Otherwise, he writes down pn1p'_{n-1} and removes pnp'_n from the permutation.

At the end, Farmer Nhoj will have written down N1N - 1 integers h1,h2,,hN1h_1, h_2, \dots, h_{N-1}, in that order. Given hh, Farmer John wants to enlist your help to reconstruct the lexicographically minimum pp consistent with Farmer Nhoj's hints, or determine that Farmer Nhoj must have made a mistake. Recall that if you are given two permutations pp and pp', pp is lexicographically smaller than pp' if pi<pip_i < p'_i at the first position ii where the two differ.

입력

Each input consists of TT independent test cases (1T101\le T\le 10). Each test case is described as follows:

The first line contains NN.

The second line contains N1N - 1 integers h1,h2,,hN1h_1, h_2, \dots, h_{N-1} (1hiN1\le h_i\le N).

출력

Output TT lines, one for each test case.

If there is a permutation pp of 1N1\dots N consistent with hh, output the lexicographically smallest such pp. If no such pp exists, output 1-1.

예제 입력 1

5
2
1
2
2
4
1 1 1
4
2 1 1
4
3 2 1

예제 출력 1

1 2
-1
-1
3 1 2 4
1 2 3 4

점수

Input 2: N8N\le 8Inputs 3-6: N100N\le 100Inputs 7-11: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Gold V1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.