#P3916. 图的遍历

    ID: 2853 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>搜索图论图的建立,建图强连通分量,缩点

图的遍历

Description

Given a directed graph with NN vertices and MM edges, for each vertex vv, let A(v)A(v) denote the reachable vertex with the largest index starting from vv. Now compute A(1),A(2),,A(N)A(1), A(2), \dots, A(N).

Input Format

The first line contains two integers N,MN, M, denoting the number of vertices and edges. The next MM lines each contain two integers Ui,ViU_i, V_i, representing the edge (Ui,Vi)(U_i, V_i). Vertices are labeled 1,2,,N1, 2, \dots, N.

Output Format

One line with NN integers A(1),A(2),,A(N)A(1), A(2), \dots, A(N).

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

Hint

  • For 60%60\% of the testdata, 1N,M1031 \leq N, M \leq 10^3.
  • For 100%100\% of the testdata, 1N,M1051 \leq N, M \leq 10^5.

Translated by ChatGPT 5