Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def D(node,a):
- q = [node]
- N = len(a)
- visited = []
- res = {}
- res[node] = 0
- while q:
- node = q.pop()
- visited.append(node)
- new_q = []
- for c in range(N):
- if a[node][c] != 0:
- if c not in visited:
- new_q.append(c)
- if c in res:
- res[c] = min(res[c],res[node]+a[node][c])
- else:
- res[c] = res[node] + a[node][c]
- q = new_q
- new_q = []
- return res
- a = []
- a.append([0,7,9,0,0,14])
- a.append([7,0,10,15,0,0])
- a.append([9,10,0,11,0,2])
- a.append([0,15,11,0,6,0])
- a.append([0,0,0,6,0,9])
- a.append([14,0,2,0,9,0])
- a1 = 0
- a2 = 1
- w= D(a1,a)
- for x in w:
- print(x+1,w[x])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement