#B3609. Strongly Connected Components
Strongly Connected Components
Strongly Connected Components
Given a directed graph with $n$ nodes and $m$ edges, find all of its strongly connected components. Note that the graph may contain duplicate edges and self-loops. For each strongly connected component, output the vertices in increasing order. Finally, list the strongly connected components sorted by the smallest vertex in each component.
inputFormat
The first line contains two integers $n$ and $m$ -- the number of nodes and the number of edges respectively. The following $m$ lines each contain two integers $u$ and $v$, representing a directed edge from $u$ to $v$.
outputFormat
Output an integer $k$, representing the number of strongly connected components. Then output $k$ lines. Each line should list the vertices in one strongly connected component in increasing order, with each component ordered by its smallest vertex.
sample
5 5
1 2
2 3
3 1
3 4
4 5
3
1 2 3
4
5
</p>