We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defprims(n,edges,start):mst={start}total=0edges.sort(key=lambdax:x[2])# Prim: Add lowest weight edge that starts anywhere in the mst and ends on any of the remaining vertices (guarantees no cycles), until no vertices remain.whilelen(mst)<n:foru,v,winedges:if(uinmst)^(vinmst):mst=mst.union({u,v})total+=wbreakreturntotal
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Prim's (MST) : Special Subtree
You are viewing a single comment's thread. Return to all comments →
python3