Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree - Problem

Network Infrastructure Analysis: You're designing a critical network infrastructure connecting n cities. Given a weighted undirected graph where edges[i] = [ai, bi, weighti] represents a connection between cities ai and bi with cost weighti.

Your task is to analyze the Minimum Spanning Tree (MST) - the most cost-effective way to connect all cities. You need to classify edges into two categories:

🔴 Critical Edges: Removing these edges would increase the total MST cost (network becomes more expensive)
🟡 Pseudo-Critical Edges: These edges can appear in some MSTs but aren't essential (alternative equally good solutions exist)

Goal: Return two lists containing the indices of critical and pseudo-critical edges respectively.

Input & Output

example_1.py — Basic Network
$ Input: n = 4, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,3,4],[2,3,1],[1,3,2]]
Output: [[0,5],[1,2,3,4,6]]
💡 Note: Edge 0 connects nodes 0-1 with weight 1, and edge 5 connects nodes 2-3 with weight 1. These are critical because removing either would force using heavier alternatives. The remaining edges can appear in some MSTs but aren't essential.
example_2.py — Triangle Graph
$ Input: n = 5, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,1],[0,4,1]]
Output: [[],[0,1,2,3,4]]
💡 Note: This forms a cycle where any 4 edges can create a valid MST with weight 4. No edges are critical, but all are pseudo-critical since each can be part of an optimal solution.
example_3.py — Bridge Network
$ Input: n = 4, edges = [[0,1,1],[1,2,1],[2,3,1]]
Output: [[0,1,2],[]]
💡 Note: This is a path graph where every edge is essential for connectivity. All edges are critical, and none are merely pseudo-critical.

Constraints

  • 2 ≤ n ≤ 100
  • 1 ≤ edges.length ≤ min(200, n × (n-1) / 2)
  • edges[i].length == 3
  • 0 ≤ ai < bi < n
  • 1 ≤ weighti ≤ 1000
  • All edge weights are distinct (no duplicate weights)
  • There is no repeated edge in the graph

Visualization

Tap to expand
Find Critical and Pseudo-Critical Edges in MST INPUT 0 1 2 3 e0:1 e1:1 e5:1 e3:2 e6:2 e2:2 n = 4 cities edges = [ [0,1,1],[1,2,1],[2,3,2], [0,3,2],[0,3,4],[2,3,1], [1,3,2] ] 7 edges total ALGORITHM STEPS 1 Find Original MST Use Kruskal: MST cost = 4 (edges 0,1,5 with weights 1,1,1) 2 Test Critical Edges Remove each edge, rebuild MST If cost increases --> Critical 3 Test Pseudo-Critical Force include each edge If MST cost same --> Pseudo 4 Classify All Edges Group into two categories Edge Analysis e0: remove-->cost=5 CRIT e1: force-->cost=4 PSEUDO e2: force-->cost=4 PSEUDO e3: force-->cost=4 PSEUDO e4: force-->cost=4 PSEUDO e5: remove-->cost=5 CRIT e6: force-->cost=4 PSEUDO FINAL RESULT MST with Edge Classification 0 1 2 3 e0 e5 e1 Critical (must use) Pseudo (optional) OUTPUT [[0, 5], [1,2,3,4,6]] 2 Critical, 5 Pseudo-Critical Key Insight: Critical edges are essential - removing them increases MST cost. Pseudo-critical edges appear in some MSTs but not all. Test by: (1) removing edge and checking cost increase, (2) forcing edge inclusion and checking if MST cost remains optimal. Time: O(E^2 * log E) using Union-Find. TutorialsPoint - Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree | Optimal Solution
Asked in
Google 45
25.0K Views
Medium Frequency
~15 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen