#ABC236G. [ABC236G] Good Vertices

[ABC236G] Good Vertices

Score : 600600 points

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

4 5 3
2 3
3 4
1 2
3 2
2 2
-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.

2 1 1000000000
1 2
-1 -1