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
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.
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.
Visualization
Tap to expand
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.
Time & Space Complexity
Time Complexity
O(EΒ² log E)
For each of E edges, we run Kruskal's algorithm which takes O(E log E) time
β‘ Linearithmic
Space Complexity
O(E + V)
Space for Union-Find structure and edge sorting
β Linear Space
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
π‘
Explanation
AI Ready
π‘ Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code