백준 1753번
def dijkstra(start):
distance[start] = 0
heapq.heappush(heap, (0, start))
while heap:
print(heap)
current_distance, current_node = heapq.heappop(heap)
if distance[current_node] < current_distance:
continue
for d, n in graph[current_node]:
next_distance = d + current_distance
if next_distance < distance[n]:
distance[n] = next_distance
heapq.heappush(heap, (next_distance, n))
'프로그래밍 > Python' 카테고리의 다른 글
[Python] 백준 10773 제로 (0) | 2021.02.15 |
---|---|
[Python] 백준 2164 카드 2 (0) | 2021.02.15 |
[Python] 백준 2667 단지번호붙이기 (0) | 2021.02.10 |
[Python] 백준 1012 유기농 배추 (0) | 2021.02.10 |
[Python] BFS(너비 우선 탐색), DFS(깊이 우선 탐색) (0) | 2021.02.03 |