

For the given graph

If we remove the connection between ‘2’ and ‘4’. Then ‘4’ will not be reachable from any other server.
The first line contains an integer 'T' which denotes the number of test cases.
The first line of each test case contains two integers ‘N’ and ‘M’, denoting the number of servers and number of connections respectively.
The following ‘M’ lines contain two integers ‘U’ and ‘V’ denoting there is an undirected server-to-server connection between server ‘U’ and server ‘V’.
For each test case, print all the critical connections in any order on separate lines.
You don't need to print anything, it has already been taken care of. Just implement the given function.
1 ≤ T ≤ 10
2 ≤ N ≤ 100
N - 1 ≤ M ≤ 100
1 ≤ U, V ≤ N
Time limit: 1 sec
A simple approach is to one by one remove every connection and see if removal of this connection causes some servers to be unreachable from others. We can do this using DFS.
We are basically given an undirected graph and we need to find all the bridges in it. A bridge is defined as an edge that, when removed, makes the graph disconnected (or more precisely, increases the number of connected components in the graph). The task is to find all bridges in the given graph.
Pick an arbitrary vertex of the graph root and run DFS from it. Note the following fact (which is easy to prove):
Now we have to learn to check this fact for each vertex efficiently. We'll use "time of entry into node" computed by the depth-first search.
So, let ‘tIn[u]’ denote entry time for node u. We introduce an array ‘low’ which will let us check the fact for each vertex u. ‘low[u]’ is the minimum of ‘tIn[u]’, the entry times ‘tIn[p]’ for each node p that is connected to node u via a back-edge (u, p) and the values of ‘low[v]’ for each vertex v which is a direct descendant of u in the DFS tree:
Now, there is a back edge from vertex u or one of its descendants to one of its ancestors if and only if vertex u has a child v for which low[v] ≤ in[u]. If low[v] = tIn[u], the back edge comes directly to u, otherwise it comes to one of the ancestors of u.
Thus, the current edge (u, v) in the DFS tree is a bridge if and only if low[v] >tIn[u].