|@Rahul Jadhav 1||458|
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.
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).
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)
1 2 2 0 2 2
1 2 2 3 3 1
0,3 2 1,
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.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes