Associated Course(s):
Must Do Interview Preparation

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

**Input:**

The first line of the input consist of 'T' denoting the number of test cases. Each test case consist of two lines, the first line of each test case consist two integers N and M, denoting the number of vertices and edges respectively. Then 'M' lines follows where each line consist 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 seperated by a space(' ') and each strongly connected components are seperated 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,

Author: vikikkdi

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

cs_abhi | 62 |

kya_bolti_public | 56 |

Shubhankar Sharma | 44 |

vermaankush14291 | 42 |

coderquill | 40 |

PiyushPandey4 | 856 |

john_wick | 757 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

UsfShilpa | 536 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.