1039. Critical Connections — Bridges in Graph

MediumGraphsMSTDFSGraph

Given an undirected graph with n nodes and a list of edges, return all critical connections (bridges) — edges whose removal increases the number of connected components. Return each bridge as [min, max] and the whole list sorted in ascending order. The input is JSON {n, edges}.

Input: JSON {n, edges}.

Output: Nested array — the sorted bridges.

Examples

Example 1
Input: {"n":4,"edges":[[0,1],[1,2],[2,0],[1,3]]}
Output: [[1,3]]
Explanation: Only edge 1-3 is a bridge.
Example 2
Input: {"n":3,"edges":[[0,1],[1,2],[2,0]]}
Output: []
Explanation: A cycle has no bridge.
Example 3
Input: {"n":3,"edges":[[0,1],[1,2]]}
Output: [[0,1],[1,2]]
Explanation: Both chain edges are bridges.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →