Count strongly connected components · Compiler

Count strongly connected components

Count the strongly connected components of a directed graph. A component is a maximal group in which each vertex can reach every other vertex along directed edges. A vertex reaches itself by a path of length zero.

Input
The first line contains n m. Vertices are numbered 0 through n-1 (1 <= n <= 50, 0 <= m <= 200). Each of the next m lines contains u v for an edge from u to v. Endpoints differ and each ordered pair occurs at most once.
Output
Print the number of strongly connected components, counting isolated vertices.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…