P21807 [GeeksforGeeks] Strongly connected components kosarajus algo
普及
题目描述

Given a Directed Graph with V vertices (Numbered from 0 to V-1) and E edges, Find the number of strongly connected components in the graph.

Example 1:
Input:
Output:
3
Explanation:
We can clearly see that there are 3 Strongly
Connected Components in the Graph
Example 2:
Input:
Output:
1
Explanation:
All of the nodes are connected to each other.
So, there's only one SCC.

Your Task:
You don't need to read input or print anything. Your task is to complete the function kosaraju() which takes the number of vertices V and edge list of the graph as inputs and returns an integer denoting the number of strongly connected components in the given graph.

Expected Time Complexity: O(V+E).
Expected Auxiliary Space: O(V+E).

Constraints:
1 ≤ V ≤ 5000
0 ≤ E ≤ (V(V-1))
0 ≤ u, v ≤ V-1
Sum of E over all testcases will not exceed 25
10^{6}

输入格式

见题面

输出格式

见题面

样例输出
3