Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def Dijkstra(G,s):
- n = size(G)
- dist = []
- pred = []
- visited = []
- listaRistoranti = []
- for i in range(n):
- dist.append(inf)
- visited.append(False)
- pred.append(-1)
- dist[s] = 0
- for i in range(n-1):
- next = minVertex(dist,visited)
- visited[next] = True
- if kind(G,next) == "R":
- listaRistoranti.append(next)
- if len(listaRistoranti) == 3:
- return listaRistoranti
- V = neighbors(G,next) #lista degli adiacenti di next
- for [z,w] in V:
- d = dist[next] + w
- if (dist[z] > d):
- dist[z] = d
- pred[z] = next
- return listaRistoranti
- def Dijkstra(G,s,destination,k):
- n = size(G)
- dist = []
- pred = []
- visited = []
- for i in range(n):
- dist.append(inf)
- visited.append(False)
- pred.append(-1)
- dist[s] = 0
- for i in range(n-1):
- next = minVertex(dist,visited)
- visited[next] = True
- if next == destination:
- if dist[next] <= k:
- return True
- else:
- return False
- V = neighbors(G,next)
- for [z,w] in V:
- d = dist[next] + w
- if (dist[z] > d):
- dist[z] = d
- pred[z] = next
- return False
Advertisement
Add Comment
Please, Sign In to add comment