Critical Connection
You are given a network with ‘N’ system nodes [0 to N - 1] and ‘M’ connection. Your task is to find out all critical connections in a given network.
Note: A connection between node ‘u’ and ‘v’ is said to be a critical connection, if after removal of a connection ‘u’ - ‘v’, there is no connection between node ‘u’ and ‘v’ and the network goes down.
For example:
For given N = 4, M = 4,
The connection between system node 0 and 1 is a critical connection.
Input Format:
The first line contains one positive integer ‘T’, denoting the number of test cases, then ‘T’ test case follow
The first line of each test case contains two integers ‘N’ and ‘M’, denoting the number of system nodes and the number of connections.
The next ‘M’ line contains two space-separated integers ’u’ and ‘v’, denoting the connection between ‘u’ and ‘v’.
Output Format:
The first line of each test case contains one integer ‘X’, denoting the number of critical connections.
The next ‘X’ lines contain two space-separated integers ’u’ and ‘v’, denoting critical connection between ‘u’ and ‘v’and ‘u’ is smaller than ‘v’.
The output of each test case will be printed on a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
1 <= N, M <= 10 ^ 6
0 <= u, v <= N - 1
There are no repeated connections.
Time Limit: 1 sec.
CodingNinjas
author
2y
Bridge in a graph
If we observe carefully the critical connection is a similar bridge in a graph(edge whose removal increases the number of components in a graph).
The idea is to do Depth first search(...read more
Help your peers!
Add answer anonymously...
Top Amazon Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Amazon Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app