I have a graph represented with adjacency lists and his MST represented by parent array.
My problem is that I need to delete an edge from the graph and update parent array.
I’ve already manage to do the cases when:
- the edge doesn’t exist;
- the edge is in graph but not in MST (MST doesn’t change);
- and the edge is the only path from two nodes(in this case I return null, because the
graph is not connected).
What can I do when the edge is in MST and the edge in graph is in a cycle? I need to do this in O(n+m) complexity.
I write the costs of edges with red color.

Just search the minimum-distance path of
the now-disconnected tree portion
to the rest of the tree and
add that path in between– which is a single edge.
Say your original tree is T. With the removal
of the edge, it is now split into trees T1 and T2.
Take one of these– say T2.
Every edge incident to a node on T2 is either
on T2 or is one connecting T2 to T1. Among these
edges incident to a node on T2, pick the one which
( (has its other end at a T1 node) and
(has the minimum cost among all such edges) ).
Search for this edge, say e=(u,v), takes O(|E|) time. O(|N|) if the separated portion is a leaf.
if there were a tree, say T’, with less cost than T1 \union T2 \union {e},
then the node sets N1 and N2 of T1 and T2 would have more inter-connections than just one edge,
i.e., there would be two or more more edges on T’ that begin at a node in N1 and end at a node in N2.
Otherwise, ( (T1 and T2 are minimum spanning trees resply. over N1 and N2) and (e is the least costly
connection between T1 and T2) ) would be false. But then, any go-between T1 and T2 is costlier than e=(u,v)– contradicts.
Skipped some proof details. hope this helps.