From 7e1bc04e775f5c635579869c8a63eb50c127f3f3 Mon Sep 17 00:00:00 2001 From: Arina Dohadailo Date: Fri, 27 Nov 2026 00:32:05 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20u10/najkratsia=5Fcesta.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- u10/najkratsia_cesta.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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