Permutation Construction
시간 제한1초메모리 제한2048 MB
각 위치 i마다 오른쪽에서 P_i보다 큰 값이 처음 나타나는 위치(없으면 -1)가 주어질 때, 이를 만족하는 1부터 N까지의 순열을 만들거나 불가능하면 -1을 출력한다.
문제
Adrian challenges you to construct a permutation of to (inclusive) that satisfies his requirements. Suppose that your permutation is denoted as . There are requirements, numbered from to . Requirement is represented by , which can be one of the followings:
- if , then there is no that satisfy and ; or
- if , then is the smallest index larger than that satisfy .
Construct any permutation that satisfies all of the requirements, or tell Adrian if it is impossible to construct such a permutation.
Note that a permutation of to (inclusive) is a sequence where each integer from to appears in the sequence exactly once.
입력
Input begins with an integer (). The next line contains integers ( or ) representing the given requirements.
출력
If at least one permutation that satisfies all the requirements can be found, output space-separated integers in a single line representing the permutation. If there are several permutations that satisfy all of the requirements, output any of them.
If there is no permutation that satisfies all the requirements, output -1 in a single line.