stronglyConnectedComponents

open fun stronglyConnectedComponents(): List<List<T>>

Identifies groups where each node is reachable from every other node in the group.

It does this by creating a reversed graph by reversing the direction of all edges in the graph. Then, it performs a topological sort on the reversed graph to determine the order of processing nodes. Now it can run a depth-first search (DFS) on the original graph in the order determined by the topological sort. Nodes visited during each DFS traversal belong to the same strongly connected component.

Return

A list of strongly connected components, where each component is a list of nodes.