TRT
Sign in
hardAdvancedLeetCode#Kruskal#remove or force one edge

Find critical and pseudo-critical edges in a minimum spanning tree

Classify each edge as in every minimum spanning tree, in some, or in none, by rerunning Kruskal with the edge removed or forced in.

The Runtime Theory Team1 min read
Taught inKruskal's algorithmPro — members onlyA minimum spanning tree connects every vertex at the lowest total edge weight. Kruskal's algorithm sorts the edges and takes each one that joins two different components, with union-find deciding in nearly constant time.
Solve it

Solving happens on the judge — come back and mark it done

Sample cases

inn = 5, edges = [[0, 1, 1], [1, 2, 1], [2, 3, 2], [0, 3, 2], [0, 4, 3], [3, 4, 3], [1, 4, 6]]

out[[0, 1], [2, 3, 4, 5]]

inn = 4, edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [0, 3, 1]]

out[[], [0, 1, 2, 3]]

inn = 3, edges = [[0, 1, 1], [1, 2, 2], [0, 2, 3]]

out[[0, 1], []]

Given a connected weighted graph with n vertices and edges[i] = (u, v, w), return two lists of edge indexes: the critical edges, which appear in every minimum spanning tree, and the pseudo-critical edges, which appear in some but not all.

Before you code

Compute the MST weight once. How does the minimum change if an edge is removed from the graph, and what does it mean if forcing an edge into the tree still reaches the same minimum?

Hints

  1. Sort the edge indexes by weight once, keeping each edge's original index.
  2. Write a Kruskal that can skip one edge, or start with one edge already unioned and counted.
  3. An edge is critical if skipping it raises the weight or leaves the graph disconnected.
  4. Otherwise, it is pseudo-critical if forcing it in first still gives the minimum weight.

Production & complexity notes

When solving Find critical and pseudo-critical edges in a minimum spanning tree on LeetCode (hard), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Kruskal's algorithm to reinforce the underlying pattern.

What it practices

Kruskal's algorithm and the role of ties, from Kruskal's algorithm.

Not started

Sign in to save your learning progress.

Sign in to save