Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #N вершин, M ребер
- N, M = map(int, input('Num of vertex and edge \n').split())
- Edges = []
- for i in range(M):
- start, end, weight = map(int, input('startedge, endedge, weight \n').split())
- Edges.append([weight, start, end])
- Edges.sort()
- MST = []
- Comp = [i for i in range(N)]
- Ans = 0
- for weight, start, end in Edges:
- if Comp[start] != Comp[end]:
- MST.append((start,end))
- Ans += weight
- a = Comp[start]
- b = Comp[end]
- for i in range(N):
- if Comp[i] == b:
- Comp[i] = a
- print(MST)
Add Comment
Please, Sign In to add comment