No.1373 Directed Operations
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もしくは右上の雲マークをクリックしてアカウントを作成してください。
leaf_1415
wotsushi