#K13201. Counting Strongly Connected Components
Counting Strongly Connected Components
Counting Strongly Connected Components
Given a directed graph representing friendships, each node denotes a person and each directed edge ((u, v)) indicates that person (u) can send a message directly to person (v). A strongly connected component (SCC) is defined as a maximal set of nodes such that for every pair (u) and (v) in the set, there exists a path from (u) to (v) and vice versa.
Input is provided via STDIN. The first line contains two integers (n) and (m), representing the number of nodes and the number of edges, respectively. The following (m) lines each contain two integers (u) and (v) that describe a directed edge from node (u) to node (v). Your task is to compute and print the number of strongly connected components in the graph.
inputFormat
The input is received via STDIN. The first line contains two integers (n) and (m) where (n) is the number of nodes and (m) is the number of directed edges. Each of the next (m) lines contains two space-separated integers (u) and (v), representing a directed edge from node (u) to node (v).
outputFormat
Output a single integer on STDOUT, which is the number of strongly connected components in the given graph.## sample
5 5
1 2
2 3
3 1
3 4
4 5
3