https://www.acmicpc.net/problem/5972
import sys, heapq
input = sys.stdin.readline
n, m = map(int,input().split())
links = [[] for _ in range(n+1)]
dist = [float('inf')] * (n+1)
for _ in range(m):
s, e, cost = map(int,input().split())
links[s].append((e, cost))
links[e].append((s, cost))
def d(start):
q = []
heapq.heappush(q,(0,start))
dist[start] = 0
while q:
cost, node = heapq.heappop(q)
if cost > dist[node]:
continue
for nxt, w in links[node]:
if dist[node] + w < dist[nxt]:
dist[nxt] = dist[node] + w
heapq.heappush(q,(dist[nxt],nxt))
d(1)
print(dist[n])
'백준' 카테고리의 다른 글
백준 11054. 가장 긴 바이토닉 부분 수열 (0) | 2024.11.28 |
---|---|
백준 2631. 줄세우기 (0) | 2024.11.28 |
백준 11657. 타임머신 (0) | 2024.11.25 |
백준 1446. 지름길 (0) | 2024.11.23 |
백준 2116. 주사위 쌓기 (1) | 2024.11.21 |