Skip to content

Commit eb181c3

Browse files
author
JangHongJoon
committed
리뷰 풀이
1 parent 62f5587 commit eb181c3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

wkdghdwns199/리뷰풀이/ACM-1753.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sys
2+
from heapq import *
3+
4+
input=sys.stdin.readline
5+
6+
vertex, edge = map(int, input().split())
7+
start_vertex = int(input())
8+
graph = {v : [] for v in range(1,vertex+1)}
9+
for _ in range(edge) :
10+
start, end, weight = map(int, input().split())
11+
graph[start].append((end, weight))
12+
13+
heap = []
14+
result = [int(1e9)] * (vertex+1)
15+
result[start_vertex] = 0
16+
heappush(heap, (start_vertex,0))
17+
18+
while heap :
19+
20+
current_node, current_weight = heappop(heap)
21+
if result[current_node] < current_weight :
22+
continue
23+
for node, weight in graph[current_node]:
24+
distance = current_weight + weight
25+
if distance < result[node]:
26+
result[node] = distance
27+
heappush(heap, (node, distance))
28+
29+
for i in range(1,vertex+1):
30+
if result[i] == int(1e9):
31+
print('INF')
32+
else :
33+
print(result[i])
34+
35+

0 commit comments

Comments
 (0)