
안녕하세요. 5주차 과제 중 최소 비용으로 도시 여행하기 문제
올려주신 답안을 보고 코드를 보완하는 중에 궁금한 점이 생겨 질문 드립니다.

문제에서는 모든 도로가 양방향이라는 조건이 있는데 위와 같이 작성했을 때는 단방향으로 표현된 것으로 생각되어서요
제가 제대로 이해한 것이 맞는지 궁금합니다!
작성한 코드 및 에러 메세지
import heapq
def dijkstra(graph, start, end):
# 거리 정보를 무한대로 초기화합니다.
distances = {node: float('infinity') for node in range(1, len(graph) + 1)}
distances[start] = 0 # 시작 노드의 거리는 0입니다.
queue = [(0, start)] # 우선순위 큐 초기화
while queue:
current_distance, current_node = heapq.heappop(queue)
# 현재 노드의 거리가 이미 알고 있는 거리보다 크면 무시합니다.
if distances[current_node] < current_distance:
continue
for adjacent, weight in graph[current_node].items():
distance = current_distance + weight
# 인접 노드까지의 거리가 현재 알고 있는 거리보다 짧으면 업데이트합니다.
if distance < distances[adjacent]:
distances[adjacent] = distance
heapq.heappush(queue, (distance, adjacent))
return distances[end]
# 그래프를 인접 리스트로 표현합니다.
graph = {
1: {2: 4, 3: 2},
2: {3: 5, 4: 1},
3: {4: 7},
4: {}
}
A, B = 1, 4
print(dijkstra(graph, A, B))
