You can change the problem a little while the result is the same.
- Get the structure of the original MST, run DFS from each vertex and you can get the maximum weighted edge in the tree structure between each Vertice pair. The complexity of this step is O (N ^ 2)
- Instead of changing one edge weight to w, we can assume that we are adding a new edge (u, v) to the original MST whose weight is equal to w. adding an edge will make a loop on the tree, and we need to cut one edge on the loop to generate a new MST. Obviously, we can compare the edge of the addition with the maximum edge in the path (a, b), The complexity of this step is O (1)
source share