Обновить u10/najkratsia_cesta.py
This commit is contained in:
parent
92fcf48643
commit
7e1bc04e77
@ -11,3 +11,19 @@ def shortest_path(number_of_nodes, connections):
|
|||||||
|
|
||||||
distances[0] = 0
|
distances[0] = 0
|
||||||
paths[0] = [0]
|
paths[0] = [0]
|
||||||
|
for i in range(number_of_nodes):
|
||||||
|
current = -1
|
||||||
|
|
||||||
|
for j in range(number_of_nodes):
|
||||||
|
if not visited[j]:
|
||||||
|
if current == -1 or distances[j] < distances[current]:
|
||||||
|
current = j
|
||||||
|
|
||||||
|
if current == -1 or distances[current] == float('inf'):
|
||||||
|
break
|
||||||
|
|
||||||
|
visited[current] = True
|
||||||
|
|
||||||
|
for neighbor, weight in graph[current]:
|
||||||
|
new_distance = distances[current] + weight
|
||||||
|
new_path = paths[current] + [neighbor]
|
||||||
Loading…
Reference in New Issue
Block a user