問題一覧 > 通常問題

No.1373 Directed Operations

レベル : / AI推定難易度 : 1125 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 173
作問者 : leaf_1415 / テスター : wotsushi
お気に入りにしたユーザー ProblemId : 5306 / 自分の提出
問題文最終更新日: 2021-02-04 03:18:14
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 281 (順位表) の他の問題:

Problem Statement

There is a graph with $N$ vertices and $0$ edges.
The $N$ vertices are called vertex $1$, vertex $2$, $\ldots$, vertex $N$.
 
You are also given a sequence of positive integers $a_1, a_2, \ldots, a_{N-1}$ of length $N-1$.
You perform the $N-1$ operations, from "Operation $1$" to "Operation $N-1$",
exactly $1$ time each, in the order Operation $1$, Operation $2$, $\ldots$, Operation $N-1$.
In Operation $i$, you choose an integer $x$ satisfying $1 \leq x \leq N - a_i$ and add a directed edge from vertex $x$ to vertex $x+a_i$.

In the graph after all $N-1$ operations are finished, you want every vertex to be reachable from vertex $1$ by following $0$ or more directed edges.
Determine whether this is possible, and if it is, show one such sequence of operations.

Input

$N$
$a_1\ a_2\ \cdots\ a_{N-1}$

$2 \leq N \leq 10^5$
$1 \leq a_i \leq N-1$
All input values are integers.

Output

If it is impossible to make every vertex reachable from vertex $1$, print "NO" on line $1$.
If it is possible to make every vertex reachable from vertex $1$, print "YES" on line $1$, and then print the sequence of operations over $N-1$ lines, from line $2$ to line $N$.
Specifically, for each integer $i$ satisfying $1 \leq i \leq N-1$, print the integer $x$ chosen in Operation $i$ on line $i+1$.
If there are multiple valid sequences of operations, any of them will be accepted.
Whether you print "YES" or "NO", end the output with a newline.

Sample

Sample 1
Input
4
2 1 2
Output
YES
1
1
2

In Operation $1$, add a directed edge from vertex $1$ to vertex $3$.
In Operation $2$, add a directed edge from vertex $1$ to vertex $2$.
In Operation $3$, add a directed edge from vertex $2$ to vertex $4$.
As a result, all vertices are reachable from vertex $1$.

Sample 2
Input
4
3 3 3
Output
NO

In each of the $3$ operations, the only possible choice is to add a directed edge from vertex $1$ to vertex $4$,
so it is impossible to make all vertices reachable from vertex $1$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。