pub fn kosaraju()
Expand description

Performs Kosaraju’s algorithm on a given directed graph represented as an adjacency list. Prints a vector of vectors, where each inner vector contains the nodes of a strongly connected component in sorted order.

Input

  • Number of vertices - Number of vertices in the graph. When this is 0, the output will be an empty vector.
  • Number of neighbors for each vertex
  • Next neighbor for each vertex

Output

Prints Strongly connected components(SCC) of the graph

Sample input

Please Enter Number of Vertices : 6
Please enter the number of neighbors for vertex 0 : 1
Please enter the next neighbor for vertex 0 : 1
Please enter the number of neighbors for vertex 1 : 1
Please enter the next neighbor for vertex 1 : 2
Please enter the number of neighbors for vertex 2 : 2
Please enter the next neighbor for vertex 2 : 0
Please enter the next neighbor for vertex 2 : 3
Please enter the number of neighbors for vertex 3 : 1
Please enter the next neighbor for vertex 3 : 4
Please enter the number of neighbors for vertex 4 : 1
Please enter the next neighbor for vertex 4 : 5
Please enter the number of neighbors for vertex 5 : 1
Please enter the next neighbor for vertex 5 : 3

Sample output

The strongly connected components are:
[[0, 1, 2], [3, 4, 5]]