102366: [AtCoder]ABC236 G - Good Vertices

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

We have a directed graph with $N$ vertices. The $N$ vertices are called Vertex $1$, Vertex $2$, $\ldots$, Vertex $N$. At time $0$, the graph has no edge.

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

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

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

Constraints

  • $2 \leq N \leq 100$
  • $1 \leq T \leq N^2$
  • $1 \leq L \leq 10^9$
  • $1 \leq u_t, v_t \leq N$
  • $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:

$N$ $T$ $L$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_T$ $v_T$

Output

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

$X_1$ $X_2$ $\ldots$ $X_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 $0$, the graph has no edge. Afterward, edges are added as follows.

  • At time $1$, a directed edge from Vertex $2$ to Vertex $3$ is added.
  • At time $2$, a directed edge from Vertex $3$ to Vertex $4$ is added.
  • At time $3$, a directed edge from Vertex $1$ to Vertex $2$ is added. Now, Vertex $4$ can be reached from Vertex $1$ in exactly three moves: $1 \rightarrow 2 \rightarrow 3 \rightarrow 4$, making Vertex $4$ good.
  • At time $4$, a directed edge from Vertex $3$ to Vertex $2$ is added. Now, Vertex $2$ can be reached from Vertex $1$ in exactly three moves: $1 \rightarrow 2 \rightarrow 3 \rightarrow 2$, making Vertex $2$ good.
  • At time $5$, a directed edge (self-loop) from Vertex $2$ to Vertex $2$ is added. Now, Vertex $3$ can be reached from Vertex $1$ in exactly three moves: $1 \rightarrow 2 \rightarrow 2 \rightarrow 3$, making Vertex $3$ good.

Vertex $1$ will never be good.


Sample Input 2

2 1 1000000000
1 2

Sample Output 2

-1 -1

Input

题意翻译

有一个有 $N$ 个节点的有向图,最开始没有一条边,接下来有 $T$ 次操作,第 $t$ 次加入一条 $u_t$ 到 $v_t$ 的有向边(可能存在自环)。 定义一个节点是好节点当且仅当能从 $1$ 号节点出发经过**恰好** $L$ 条边到达该节点。 输出每个节点成为好节点的最少操作次数,如果不能,输出 $-1$。

Output

分数:600分

问题描述

我们有一个包含 $N$ 个顶点的有向图。这 $N$ 个顶点分别称为顶点 $1$、顶点 $2$、$\ldots$、顶点 $N$。在时间 $0$ 时,图中没有边。

对于每个 $t = 1, 2, \ldots, T$,在时间 $t$,会从顶点 $u_t$ 添加一条到顶点 $v_t$ 的有向边。 (边可能是自环,即 $u_t = v_t$ 可能成立。)

当从顶点 $1$ 开始并正好移动 $L$ 次就能到达顶点时,该顶点被称为 好的

对于每个 $i = 1, 2, \ldots, N$,打印顶点 $i$ 成为好顶点的最早时间。如果顶点 $i$ 永远不会成为好顶点,打印 $-1$。

约束

  • $2 \leq N \leq 100$
  • $1 \leq T \leq N^2$
  • $1 \leq L \leq 10^9$
  • $1 \leq u_t, v_t \leq N$
  • $i \neq j \Rightarrow (u_i, v_i) \neq (u_j, v_j)$
  • 输入中的所有值都是整数。

输入

输入以标准输入的以下格式给出:

$N$ $T$ $L$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_T$ $v_T$

输出

按照以下格式,对于每个 $i = 1, 2, \ldots, N$,打印顶点 $i$ 成为好顶点的最早时间 $X_i$。如果顶点 $i$ 永远不会成为好顶点,$X_i$ 应为 $-1$。

$X_1$ $X_2$ $\ldots$ $X_N$

样例输入 1

4 5 3
2 3
3 4
1 2
3 2
2 2

样例输出 1

-1 4 5 3

在时间 $0$ 时,图中没有边。之后,边按以下方式添加。

  • 在时间 $1$,从顶点 $2$ 到顶点 $3$ 添加一条有向边。
  • 在时间 $2$,从顶点 $3$ 到顶点 $4$ 添加一条有向边。
  • 在时间 $3$,从顶点 $1$ 到顶点 $2$ 添加一条有向边。现在,可以从顶点 $1$ 出发,正好移动三次到达顶点 $4$: $1 \rightarrow 2 \rightarrow 3 \rightarrow 4$,使顶点 $4$ 变为好顶点。
  • 在时间 $4$,从顶点 $3$ 到顶点 $2$ 添加一条有向边。现在,可以从顶点 $1$ 出发,正好移动三次到达顶点 $2$: $1 \rightarrow 2 \rightarrow 3 \rightarrow 2$,使顶点 $2$ 变为好顶点。
  • 在时间 $5$,从顶点 $2$ 到顶点 $2$ 添加一条有向边(自环)。现在,可以从顶点 $1$ 出发,正好移动三次到达顶点 $3$: $1 \rightarrow 2 \rightarrow 2 \rightarrow 3$,使顶点 $3$ 变为好顶点。

顶点 $1$ 永远不会变为好顶点。


样例输入 2

2 1 1000000000
1 2

样例输出 2

-1 -1

加入题单

算法标签: