#abc236g. [abc236_g]Good Vertices

[abc236_g]Good Vertices

Problem Statement

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

For each t=1,2,ldots,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,ldots,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

  • 2leqNleq1002 \\leq N \\leq 100
  • 1leqTleqN21 \\leq T \\leq N^2
  • 1leqLleq1091 \\leq L \\leq 10^9
  • 1lequt,vtleqN1 \\leq u_t, v_t \\leq N
  • ineqjRightarrow(ui,vi)neq(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\\vdots uTu_T vTv_T

Output

In the following format, for each i=1,2,ldots,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\\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: 1rightarrow2rightarrow3rightarrow41 \\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: 1rightarrow2rightarrow3rightarrow21 \\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: 1rightarrow2rightarrow2rightarrow31 \\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