#graph101. 强连通分量

强连通分量

Strongly Connected Components

Problem Description

Given a graph with nn vertices and mm edges, output all of its strongly connected components.

Input Format

The first line contains two integers $n, m\ (1 \le n \le 10^5,\ 1 \le m \le 3 \times 10^5)$. The next mm lines each contain two integers u,v (1≤u,v≤n)u, v\ (1 \le u, v \le n).

Output Format

Output several lines, each with several numbers representing one strongly connected component, with the vertices inside a component printed in ascending order. For all the strongly connected components, output them in ascending lexicographic order.

Sample Input

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

Sample Output

1 3
2 4 5