28 · Union-Find & Minimum Spanning Trees

#1489 Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree

Hardsolve on LeetCode ↗

frequently reported atMeta

the problem

In plain words

Given a connected weighted undirected graph, return two lists of edge indices: critical edges (removing it makes every MST heavier) and pseudo-critical edges (in some MST but not all).

in n = 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]]

Edges 0 and 1 appear in every MST; 2–5 appear in some.

in n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]

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

Any 3 of the 4 equal edges form an MST.

  • 2 ≤ n ≤ 100
  • 1 ≤ edges.length ≤ min(200, n(n−1)/2)
  • 1 ≤ weight ≤ 1000
  • The graph is connected

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #1584
      Min Cost to Connect All Points
      Mediumin Union-Find & MST
    2. #684
      Redundant Connection
      Mediumin Union-Find & MST