atcoder#ABC236G. [ABC236G] Good Vertices
[ABC236G] Good Vertices
Score : points
Problem Statement
We have a directed graph with vertices. The vertices are called Vertex , Vertex , , Vertex . At time , the graph has no edge.
For each , at time , a directed edge from Vertex to Vertex will be added. (The edge may be a self-loop, that is, may hold.)
A vertex is called good when it can be reached by starting at Vertex and traversing an edge exactly times.
For each , print the earliest time when Vertex is good. If there is no time when Vertex is good, print instead.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
In the following format, for each , print the earliest time when Vertex is good. If there is no time when Vertex is good, should be .
4 5 3
2 3
3 4
1 2
3 2
2 2
-1 4 5 3
At time , the graph has no edge. Afterward, edges are added as follows.
- At time , a directed edge from Vertex to Vertex is added.
- At time , a directed edge from Vertex to Vertex is added.
- At time , a directed edge from Vertex to Vertex is added. Now, Vertex can be reached from Vertex in exactly three moves: , making Vertex good.
- At time , a directed edge from Vertex to Vertex is added. Now, Vertex can be reached from Vertex in exactly three moves: , making Vertex good.
- At time , a directed edge (self-loop) from Vertex to Vertex is added. Now, Vertex can be reached from Vertex in exactly three moves: , making Vertex good.
Vertex will never be good.
2 1 1000000000
1 2
-1 -1