diff --git a/u10/najkratsia_cesta.py b/u10/najkratsia_cesta.py index 59d6c3f..97660d3 100644 --- a/u10/najkratsia_cesta.py +++ b/u10/najkratsia_cesta.py @@ -10,4 +10,20 @@ def shortest_path(number_of_nodes, connections): visited = [False] * number_of_nodes distances[0] = 0 - paths[0] = [0] \ No newline at end of file + 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] \ No newline at end of file