简体   繁体   English

使用 Prim 算法的最大生成树

[英]Maximum spanning tree using Prim's algorithm

How would this algorithm be changed to give a maximum spanning tree?该算法将如何更改以提供最大生成树?

MST_prim(G,w,r)
for each u that exists in G.V
   u.key= inf 
   u.pi=NIL
r.key=0
Q=G.V
While Q is not empty 
   u= EXTRACT-MIN(Q)
for each v in G.Adj[u]
if v is in Q and w(u,v)<v.key
       v.pi=u
       v.key=w(u,v)

I tried changing it so that it would give me我试着改变它,让它给我

u = EXTRACT - MAX(Q) and w(u, v) > v.key

but I don't think that's correct.但我不认为这是正确的。

If you change all costs to negative and then find with prim mst, the answer to your questions will be abs(mst of the graph(where w = -w)).如果您将所有成本更改为负数,然后使用 prim mst 查找,那么您的问题的答案将是 abs(mst of the graph(where w = -w))。 I think this is the easiest way...我认为这是最简单的方法...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM