Skip to content
AI360Xpert
Beta
Difficulty: HardAdvanced Graphs

Critical Connections in a Network

Problem in Plain English

Find every undirected network connection whose removal disconnects some servers. Discovery times and low links identify these bridges in one traversal.

Problem Statement

A connected undirected network has n servers numbered from 0 to n - 1 and edges connections, where [a, b] joins two distinct servers. There are no repeated connections.

Return all connections whose removal makes some servers unable to reach others. These edges are called bridges. Edge orientation and answer order do not matter.

Constraints

  • 2 <= n <= 10^5
  • n - 1 <= connections.length <= 10^5
  • Endpoints are distinct and in [0, n - 1]; there are no repeated connections.
  • The network is connected.

Examples

Example 1

Input
n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]
Output
[[1,3]]

The triangle has an alternate route around each of its edges. Server 3 is attached only through 1, so removing 1-3 isolates it.

Example 2

Input
n = 2, connections = [[0,1]]
Output
[[0,1]]

The single connection is the only route between the two servers, so it is a bridge.

Example 3

Input
n = 3, connections = [[0,1],[1,2],[2,0]]
Output
[]

Removing any one edge leaves the other two as a path connecting all three servers. Equality of a child low link with an ancestor discovery time must not create a bridge.

Intuition

Removing a DFS tree edge disconnects its child subtree only if that subtree has no alternate route back to the parent or an earlier ancestor. In Example 1, 2 can reach 0 without using its parent edge, protecting the triangle 0-1-2. Server 3 has no such escape, so 1-3 is a bridge. A low link summarizes the earliest discovery reachable by going down tree edges and then taking one non-parent edge.

Approaches

Tarjan Bridges

Optimal

Solution Details

Reveal Tarjan Bridges: intuition, complexity, and code

Hints

Hint 1
Removing an edge on a cycle cannot disconnect the network.
Hint 2
For each DFS subtree, remember the earliest ancestor it can reach without its incoming edge.
Hint 3
After a child finishes, its incoming edge is a bridge exactly when low[child] > disc[parent].

Edge Cases

  • Every edge of a chain is a bridge, including both end connections.
  • A single large cycle has no bridges; low equality is enough to protect an edge.
  • Two dense cyclic regions joined by one connection have that connection as their only bridge.

Common Mistakes and Interview Tips

  • Using >= in the bridge test falsely flags edges with an alternate route back to the parent.
  • Treating the reverse copy of the parent edge as a back edge suppresses real bridges.
  • Checking a child’s low link before its subtree finishes misses later escape edges.
  • Using SCC low-link rules for this undirected problem confuses two different stack invariants.

Key Takeaway

A DFS subtree needs only its earliest alternate escape to decide whether its incoming edge is essential. Low links summarize that escape information in linear time.