Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 43s1 days 16 hours 1 minutes 43 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 43s1 days 16 hours 1 minutes 43 seconds.

Sign in to watch this lesson
Advanced - Graphs · 4:02
The cheapest spanning tree that costs strictly more than the minimum differs from a minimum spanning tree by one swap: add a non-tree edge and remove an edge on the cycle it closes. Banning each tree edge and rerunning Kruskal finds it in O(VE); taking, for every non-tree edge, the heaviest tree edge on its path through the LCA finds it in O(E log V) with binary lifting, as long as we fall back to the strict second maximum when the maximum ties the new edge. The same path maximum gives the cheapest tree that must contain a given edge.