Problem Description
Given a weighted undirected connected graph with n vertices (labeled from 0 to n - 1) and an edge list, determine all critical and pseudo-critical edges in its Minimum Spanning Tree (MST). A critical edge is one whose removal increases the MST's total weight, while a pseudo-critical edge is one that can appear in some MSTs but not all.
Key Insights
- Use Kruskal's algorithm to compute the MST.
- Sort the edges by weight and use Union-Find to efficiently detect cycles.
- Compute the baseline MST weight.
- For each edge, test if excluding it increases the MST weight (critical edge).
- For each edge, test if forcing its inclusion can still produce an MST with the same weight (pseudo-critical edge).
Space and Time Complexity
Time Complexity: O(E^2 * α(N)) where E is the number of edges and α is the inverse Ackermann function. Space Complexity: O(N + E) for the Union-Find data structure and edge storage.
Solution
The solution uses Kruskal's algorithm along with a Union-Find (Disjoint Set Union) data structure:
- Compute the baseline MST weight by sorting the edges and applying Kruskal’s algorithm.
- For every edge:
- To check if it is critical, recompute the MST without the edge. If the resulting weight increases or the MST cannot be formed, the edge is critical.
- To check if it is pseudo-critical, force the inclusion of the edge and then compute the MST. If the resulting total weight equals the baseline MST weight, the edge is pseudo-critical. This requires careful manipulation of the Union-Find structure and multiple MST computations.