#abc236g. G - Good Vertices

G - Good Vertices

Score : 600600 points

问题描述

我们有一个包含 NN 个顶点的有向图。这 NN 个顶点分别称为顶点 1、顶点 2、……、顶点 NN。在时间 00,该图没有任何边。

对于每个时刻 t=1,2,,Tt = 1, 2, \ldots, T,在时间 tt,将从顶点 utu_t 到顶点 vtv_t 添加一条有向边。(这条边可以是自环,即可能存在 ut=vtu_t = v_t 的情况。)

若一个顶点可以从顶点 1 出发,沿着边 恰好 走过 LL 次到达,则称这个顶点为 顶点。

对于每个 i=1,2,,Ni = 1, 2, \ldots, N,请输出顶点 ii 首次成为好顶点的时间。如果顶点 ii 从未成为好顶点,请输出 1-1

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a directed graph with NN vertices. The NN vertices are called Vertex 11, Vertex 22, \ldots, Vertex NN. At time 00, the graph has no edge.

For each t=1,2,,Tt = 1, 2, \ldots, T, at time tt, a directed edge from Vertex utu_t to Vertex vtv_t will be added. (The edge may be a self-loop, that is, ut=vtu_t = v_t may hold.)

A vertex is called good when it can be reached by starting at Vertex 11 and traversing an edge exactly LL times.

For each i=1,2,,Ni = 1, 2, \ldots, N, print the earliest time when Vertex ii is good. If there is no time when Vertex ii is good, print 1-1 instead.

Constraints

  • 2N1002 \leq N \leq 100
  • 1TN21 \leq T \leq N^2
  • 1L1091 \leq L \leq 10^9
  • 1ut,vtN1 \leq u_t, v_t \leq N
  • ij(ui,vi)(uj,vj)i \neq j \Rightarrow (u_i, v_i) \neq (u_j, v_j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN TT LL

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uTu_T vTv_T

Output

In the following format, for each i=1,2,,Ni = 1, 2, \ldots, N, print the earliest time XiX_i when Vertex ii is good. If there is no time when Vertex ii is good, XiX_i should be 1-1.

X1X_1 X2X_2 \ldots XNX_N

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 00, the graph has no edge. Afterward, edges are added as follows.

  • At time 11, a directed edge from Vertex 22 to Vertex 33 is added.
  • At time 22, a directed edge from Vertex 33 to Vertex 44 is added.
  • At time 33, a directed edge from Vertex 11 to Vertex 22 is added. Now, Vertex 44 can be reached from Vertex 11 in exactly three moves: 12341 \rightarrow 2 \rightarrow 3 \rightarrow 4, making Vertex 44 good.
  • At time 44, a directed edge from Vertex 33 to Vertex 22 is added. Now, Vertex 22 can be reached from Vertex 11 in exactly three moves: 12321 \rightarrow 2 \rightarrow 3 \rightarrow 2, making Vertex 22 good.
  • At time 55, a directed edge (self-loop) from Vertex 22 to Vertex 22 is added. Now, Vertex 33 can be reached from Vertex 11 in exactly three moves: 12231 \rightarrow 2 \rightarrow 2 \rightarrow 3, making Vertex 33 good.

Vertex 11 will never be good.

Sample Input 2

2 1 1000000000
1 2

Sample Output 2

-1 -1

update @ 2024/3/10 10:14:40