⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 30s17 days 22 hours 19 minutes 30 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 30s17 days 22 hours 19 minutes 30 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.