8000 Update second_best_mst.md · cp-algorithms/cp-algorithms@230b5c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 230b5c2

Browse files
erikouiadamant-pwn
authored andcommitted
Update second_best_mst.md
I was following the text description and couldn't figure out the cycle part(step 2). I hope this small note helps other people like me.
1 parent 7df7fcc commit 230b5c2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/graph/second_best_mst.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Here we will do the exact opposite.
3737
We try to add every edge that is not already in the MST.
3838

3939
1. Sort the edges in $O(E \log E)$, then find a MST using Kruskal in $O(E)$.
40-
2. For each edge $e$ not already in the MST, temporarily add it to the MST, creating a cycle.
41-
3. Find the edge $k$ with maximal weight in the cycle that is not equal to $e$.
40+
2. For each edge $e$ not already in the MST, temporarily add it to the MST, creating a cycle. The cycle will pass through the LCA.
41+
3. Find the edge $k$ with maximal weight in the cycle that is not equal to $e$, by following the parents of the nodes of edge $e$, up to the LCA.
4242
4. Remove $k$ temporarily, creating a new spanning tree.
4343
5. Compute the weight difference $\delta = weight(e) - weight(k)$, and remember it together with the changed edge.
4444
6. Repeat step 2 for all other edges, and return the spanning tree with the smallest weight difference to the MST.

0 commit comments

Comments
 (0)
0