깜빡하고 시간 안잼..
import sys
import heapq
input = sys.stdin.readline
INF = sys.maxsize
v, e = list(map(int, input().rstrip().split()))
s = int(input().rstrip())
graph = [[] for _ in range(v + 1)]
dist = [INF] * (v + 1)
for i in range(e):
a, b, c = list(map(int, input().rstrip().split()))
graph[a].append((b, c))
def dijkstra(start):
q = []
heapq.heappush(q, (0, start))
dist[start] = 0
while q:
cost, now = heapq.heappop(q)
if dist[now] < cost:
continue
for i in graph[now]:
next = cost + i[1]
if next < dist[i[0]]:
dist[i[0]] = next
heapq.heappush(q, (next, i[0]))
dijkstra(s)
for i in range(1, v + 1):
if dist[i] >= INF:
print('INF')
else:
print(dist[i])
완전 다익스트라 문제 그잡채였다!
플로이드 워셜이랑 다르게 코드가 조금 길어서 복습을 여러번해야할둣