#abc236g. G - Good Vertices
G - Good Vertices
Score : points
问题描述
我们有一个包含 个顶点的有向图。这 个顶点分别称为顶点 1、顶点 2、……、顶点 。在时间 ,该图没有任何边。
对于每个时刻 ,在时间 ,将从顶点 到顶点 添加一条有向边。(这条边可以是自环,即可能存在 的情况。)
若一个顶点可以从顶点 1 出发,沿着边 恰好 走过 次到达,则称这个顶点为 好 顶点。
对于每个 ,请输出顶点 首次成为好顶点的时间。如果顶点 从未成为好顶点,请输出 。
以上为通义千问 qwen-max 翻译,仅供参考。
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 .
Sample Input 1
4 5 3
2 3
3 4
1 2
3 2
2 2
Sample Output 1
-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.
Sample Input 2
2 1 1000000000
1 2
Sample Output 2
-1 -1
update @ 2024/3/10 10:14:40