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
ABCDECritical: $1MCritical: $2MAlt: $3MAlt: $2MAlt: $3MAlt: $1MNetwork Analysis Results🔴 Critical RoadsA-B: Essential backboneB-C: No alternativesRemoving increases costMust build for connectivity🟡 Pseudo-CriticalA-D, B-D, B-E, C-EAlternative valid routesSame total cost possibleFlexible implementation📊 Optimal StrategyMin Cost: $3M totalMust include: A-B, B-CChoose 2 from alternativesMultiple valid solutions
Understanding the Visualization
1
🗺️ Survey the Territory
Identify all possible road connections between cities with their construction costs
2
📊 Find Optimal Network
Use Kruskal's algorithm to determine the minimum cost to connect all cities
3
🔍 Test Road Importance
For each road, see what happens if we remove it - does cost increase?
4
🛣️ Test Alternative Routes
For non-critical roads, see if including them first still gives optimal cost
5
📋 Classify Infrastructure
Critical roads are mandatory, pseudo-critical roads are optional but viable
Key Takeaway
🎯 Key Insight: An edge is critical if removing it breaks the optimal cost, and pseudo-critical if it can be part of an optimal solution but isn't mandatory. Use Kruskal's algorithm with systematic edge testing to classify each connection efficiently.
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