문제

Can anyone think of a way to modify Kruskal's algorithm for a minimum spanning tree so that it must include a certain edge (u,v)?

도움이 되었습니까?

해결책

I might be confusing, but as far as I remember, kruskal can handle negative weights,so you can give this edge -infinity weight.

  • Of course it won't actually be -infinity, but a number low enough to be significant enough that it cannot be ignored, something like -1 * sigma(|weight(e)|) for each e in E.

다른 팁

If you can modify the graph structure, you could remove vertices u and v, and replace them with a new vertex w that has the edges u and v used to have. In the case of duplicate edges, pick the one with the smallest weight.

Provided that we know the edge weight of (u,v), we can also simply add it to the front of our sorted list of edge weights (as Kruskal sorts the edge weights in increasing order). In this case, the edge (u,v) will be the first edge included in our tree and Kruskal will run normally, finding the spanning tree of minimum weight with (u,v).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top