import sys
def dijkstra(graph, start):
n = len(graph)
visited = [False] * n
distances = [sys.maxsize] * n
distances[start] = 0
for _ in range(n):
# Знаходимо найближчу невідвідану вершину
min_distance = sys.maxsize
for i in range(n):
if not visited[i] and distances[i] < min_distance:
min_distance = distances[i]
current_vertex = i
visited
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
import sys
def dijkstra(graph, start):
n = len(graph)
visited = [False] * n
distances = [sys.maxsize] * n
distances[start] = 0
for _ in range(n):
# Знаходимо найближчу невідвідану вершину
min_distance = sys.maxsize
for i in range(n):
if not visited[i] and distances[i] < min_distance:
min_distance = distances[i]
current_vertex = i
visited