Strongly Connected Components (Kosaraju's Algo)
Submissions: 4121   Accuracy:

20.38%

  Difficulty: Medium   Marks: 4
Associated Course(s):   Interview Preparation

Given a graph with N nodes and M directed edges. Your task is to complete the function kosaraju() which returns an integer denoting the no of strongly connected components in the graph.

Input:
The first line of input contains an integer T. Then T test cases follow. Each test case contains two integers N and M . In the next line are M space separated values u,v denoting an edge from u to v.

Output:
For each test case in a new line output will an integer denoting the no of strongly connected components present in the graph.

Constraints:
1<=T<=100
1<=N,M<=100
1<=u,v<=N

Example(To be used only for expected output):
Input
:
2
5 5
2 1 1 3 3 2 1 4 4 5
3 3
1 2 2 3 3 1
Output:
3
1

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.