Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 662 |

@arpitsatnalika | 629 |

@code_it_ | 591 |

@prakharxyz | 583 |

@tujhekya | 542 |

@Rahul Jadhav 1 | 458 |

@sivanandh03 | 448 |

@satyam0460 | 429 |

@iamronak | 424 |

@imnm | 424 |

@18eumc107 | 421 |

Complete Leaderboard |

Given an unweighted directed graph, your task is to print the members of the strongly connected component in the graph where each component is separated by ', ' (see the example for more clarity). The Graph can have loops.

**Input:**

The first line of the input consists of 'T' denoting the number of test cases. Each test case consists of two lines, the first line of each test case consist of two integers N and M, denoting the number of vertices and edges respectively. Then 'M' lines follow where each line consists of a pair of integers (u and v) representing an edge from u to v. (0 based indexing is used).

**Output:**

For each test case in a new line print the Strongly connected component of a graph. where each member of a strongly connected component is separated by a space(' ') and each strongly connected component is separated by comma (' , '). If there are many such options then print the output that will be provided by the standard implementation of the Tarjan's algorithm. (remember zero-based indexing)

**Constraints:**

1<=T<=10

1<=N<=20

1<=M<=200

0<=u,v<=N-1

**Example:**

**Input:**

2

3 3

1 2 2 0 2 2

4 3

1 2 2 3 3 1

**Output:**

0,2,1,

0,3 2 1,

**Explanation:**

**Testcase 2:**

given no of vertex :4 --> 0,1,2,3

edges are 1-->2, 2-->3, 3-->1,

There is a connected subgraph that includes 1-2-3 which satisfy the condition of strongly connecting components i.e each node is reachable from every other nodes.

Another subgraph includes individual nodes 0.

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)

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.