A connected network has n nodes 0 .. n-1 and candidate cables cables[i] = [u, v, cost]
(undirected). Among all cheapest ways to connect every node (minimum spanning trees):
- a cable is essential if it appears in every cheapest layout;
- a cable is optional if it appears in some but not all cheapest layouts.
Return [essential, optional], two sorted lists of cable indices.
Examples
Input: n = 5, cables = [[0,1,2],[1,2,2],[0,2,2],[2,3,1],[3,4,4],[2,4,5]]
Output: [[3, 4], [0, 1, 2]]
Explanation: every cheapest layout (weight 9) uses 2-3 and 3-4, plus any two of the three
cables of the triangle 0-1-2. Cable 2-4 is never used.
Input: n = 2, cables = [[0,1,5]]
Output: [[0], []]
Constraints
2 <= n <= 100,n - 1 <= len(cables) <= 300,0 <= cost <= 1000- The cables connect all nodes. Target
O(E**2 * alpha(n))after one sort.
Goals
- Compute the minimum spanning tree weight with Kruskal
- Classify an edge by re-running Kruskal without it and with it forced
- Distinguish 'in every MST' from 'in some MST'