diff --git a/u10/najkratsia_cesta.py b/u10/najkratsia_cesta.py index 2be2dde..7adbdd9 100644 --- a/u10/najkratsia_cesta.py +++ b/u10/najkratsia_cesta.py @@ -26,17 +26,20 @@ def shortest_path(number_of_nodes, connections): if j in path[i]: continue - new_dist = dist[i] + length - new_path = path[i] + [j] + newdist = dist[i] + length + newpath = path[i] + [j] bet = False if dist[j] is None: bet = True - elif new_dist < dist[j]: - bet = True + elif newdist < dist[j]: + bet = True + elif newdist == dist[j]: + if newpath < path[j]: + bet = True if bet: - dist[j] = new_dist - path[j] = new_path + dist[j] = newdist + path[j] = newpath change = True return path[end]