골드1 택배 배송 5972번 - Python, 다익스트라(Dijkstra) 출처 : https://www.acmicpc.net/problem/5972 코드 import heapqdef dijkstra(graph, start): INF = float('inf') N = len(graph) distance = [INF] * N distance[start] = 0 pq = [] heapq.heappush(pq, (start, 0)) while pq: now, dist = heapq.heappop(pq) for neighbor, weight in graph[now]: cost = dist + weight if cost 풀이 최소 비용을 구하는 문제이기에 다익스트라를 사용했습니다. .. 2025. 2. 7. 이전 1 다음