From 2333c4eaec29d12ecc61c348bc039a9089caf80d Mon Sep 17 00:00:00 2001 From: Arina Dohadailo Date: Fri, 27 Nov 2026 00:57:21 +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 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/u10/najkratsia_cesta.py b/u10/najkratsia_cesta.py index 97660d3..fb66081 100644 --- a/u10/najkratsia_cesta.py +++ b/u10/najkratsia_cesta.py @@ -26,4 +26,16 @@ def shortest_path(number_of_nodes, connections): for neighbor, weight in graph[current]: new_distance = distances[current] + weight - new_path = paths[current] + [neighbor] \ No newline at end of file + new_path = paths[current] + [neighbor] + if new_distance < distances[neighbor]: + distances[neighbor] = new_distance + paths[neighbor] = new_path + + elif new_distance == distances[neighbor]: + if paths[neighbor] is None or new_path < paths[neighbor]: + paths[neighbor] = new_path + + if paths[number_of_nodes - 1] is None: + return [] + + return paths[number_of_nodes - 1]