#P2863. Strongly Connected Components Count
Strongly Connected Components Count
Strongly Connected Components Count
Given a directed graph with n vertices and m edges, count the number of strongly connected components (SCCs) that have more than one vertex. A strongly connected component is a maximal set of vertices such that every vertex is reachable from every other vertex in the set. Only components with more than one vertex should be counted.
You can use algorithms like Tarjan's algorithm or Kosaraju's algorithm to solve this problem. The mathematical formulation is: $$\text{Answer} = |\{S: S \text{ is a SCC and } |S| > 1\}|.$$
inputFormat
The input begins with two integers n and m on the first line representing the number of vertices and edges, respectively. The following m lines each contain two integers u and v (1-indexed), indicating a directed edge from u to v.
outputFormat
Output a single integer representing the number of strongly connected components that contain more than one vertex.
sample
3 3
1 2
2 3
3 1
1