B - Find Permutation 2 Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。ここで、 A の各要素は -1 または 1 以上 N 以下の整数です。

以下の条件を全て満たす長さ N の整数列 P=(P_1,P_2,\ldots,P_N) が存在するか判定し、存在するならば一つ求めてください。

  • P(1,2,\ldots,N) を並び替えてできる整数列である。
  • i=1,2,\ldots,N に対し、 A_i \neq -1 ならば P_i=A_i が成り立つ。

制約

  • 1\le N\le 10
  • A_i=-1 または 1\le A_i \le N
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 \ldots A_N

出力

条件を全て満たす P が存在しない場合は No と出力せよ。

そうでない場合、条件を全て満たす P を以下の形式で出力せよ。

Yes
P_1 P_2 \ldots P_N

条件を全て満たす P が複数存在する場合、どれを出力しても正答となる。


入力例 1

4
-1 -1 2 -1

出力例 1

Yes
3 1 2 4

P=(3,1,2,4) とすると条件を全て満たします。

このほかにも、 P=(1,3,2,4)P=(4,3,2,1) なども条件を全て満たします。


入力例 2

5
-1 -1 1 -1 1

出力例 2

No

条件を全て満たす P は存在しません。


入力例 3

7
3 -1 4 -1 5 -1 2

出力例 3

Yes
3 7 4 1 5 6 2

Score : 200 points

Problem Statement

You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N. Here, each element of A is either -1 or an integer between 1 and N, inclusive.

Determine whether there exists an integer sequence P=(P_1,P_2,\ldots,P_N) of length N that satisfies all of the following conditions, and if it exists, find one.

  • P is a permutation of (1,2,\ldots,N).
  • For i=1,2,\ldots,N, if A_i \neq -1, then P_i=A_i holds.

Constraints

  • 1\le N\le 10
  • A_i=-1 or 1\le A_i \le N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

If there is no P that satisfies all conditions, output No.

Otherwise, output P that satisfies all conditions in the following format:

Yes
P_1 P_2 \ldots P_N

If there are multiple P that satisfy all conditions, any of them may be output.


Sample Input 1

4
-1 -1 2 -1

Sample Output 1

Yes
3 1 2 4

P=(3,1,2,4) satisfies all conditions.

Besides this, P=(1,3,2,4) or P=(4,3,2,1) also satisfies all conditions.


Sample Input 2

5
-1 -1 1 -1 1

Sample Output 2

No

There is no P that satisfies all conditions.


Sample Input 3

7
3 -1 4 -1 5 -1 2

Sample Output 3

Yes
3 7 4 1 5 6 2