Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 537 |

@akashverma4 | 291 |

@swastik8750 | 237 |

@nishunishuraj18 | 223 |

@nayan2709 | 211 |

@ajaybhardwaj1999 | 196 |

@surajmamgai | 193 |

@AnshikaPandey | 192 |

@gurshehzadsingh | 188 |

@Rajpra786 | 185 |

@shardul08 | 185 |

Complete Leaderboard |

Given a Directed Graph with V vertices and E edges, Find the members of strongly connected components in the graph.

**Example 1:**

Input:Output:0 1 2,3,4,Explanation: We can clearly see that there are 3 Strongly Connected Components in the Graph as mentioned in the Output.

**Example 2:**

Input:Output:0 1 2,Explanation: All of the nodes are connected to each other. So, there's only one SCC as shown.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **tarjans()** which takes the number of vertices V and adjacency list of the graph as input parameters and returns a list of list of integers denoting the members of strongly connected components in the given graph.

**Note: **A single strongly connected component must be represented in the form of a list if integers sorted in the ascending order. The resulting list should consist of a list of all SCCs which must be sorted in a way such that a lexicographically smaller list of integers appears first.

**Expected Time Complexity:** O(V + E).

**Expected Auxiliary Space:** O(V).

**Constraints:**

1 ≤ V ≤ 10^{5}

1 ≤ E ≤ 10^{5}

0 ≤ u, v ≤ N-1

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Strongly connected component (Tarjans's Algo)

...