Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import heapq
- from sets import Set
- import math
- def Prim(G):
- a = [math.inf] * len(G[0])
- Q = [] # priority queue
- for v in range(len(G[0])):
- heapq.heappush(Q, v)
- S = Set([]) # set of explored nodes S <- phi
- while (Q[0] != None): # Does this seem right?
- u = heapq.heappop(Q)
- S.union(u)
- for v in range(len(G[0])):
- if u == v:
- continue
- if v not in S and G[u][v] < a[v]:
- decrease priority a[v] to c_e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement