#K94517. Strongly Connected Components (SCC) Analysis
Strongly Connected Components (SCC) Analysis
Strongly Connected Components (SCC) Analysis
You are given a directed graph with N nodes and M edges. Your task is to compute two values:
- The number of strongly connected components (SCCs) in the graph.
- The size of the largest SCC.
A strongly connected component is a maximal set of vertices where every vertex is reachable from every other vertex in the same set via directed paths. In other words, for a directed graph \(G=(V,E)\), a subset \(S \subseteq V\) is strongly connected if for every pair \(u,v \in S\), there exists a path from \(u\) to \(v\) and a path from \(v\) to \(u\).
Input/Output through standard input/output.
inputFormat
The input is given from standard input and has the following format:
N M u1 v1 u2 v2 ... uM vM
Where:
N
is the number of nodes. The nodes are numbered from 1 to N.M
is the number of directed edges.- Each of the next M lines contains two integers
u
andv
representing a directed edge from u to v.
outputFormat
Print two integers separated by a space on a single line:
- The number of strongly connected components (SCCs) in the graph.
- The size of the largest SCC.
5 5
1 2
2 3
3 1
4 5
5 4
2 3