Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. def dijkstra (G,inicio):
  2. dicc={inicio:0}
  3. parent={}
  4. queue=[]
  5. queue.append(inicio)
  6. while len(queue) >0:
  7. v=queue.pop(0)
  8. for s,t,w in G.outgoing_edge_iterator(v):
  9. weight=dicc[v]+w
  10. if not t in dicc:
  11. parent[t]=v
  12. dicc[t]=weight
  13. queue.append(t)
  14. else:
  15. if weight<dicc[t]:
  16. parent[t]=v
  17. dicc[t]=weight
  18. return dicc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement