Skip to content

Commit

Permalink
리뷰 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
JangHongJoon committed Mar 27, 2024
1 parent 62f5587 commit eb181c3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions wkdghdwns199/리뷰풀이/ACM-1753.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys
from heapq import *

input=sys.stdin.readline

vertex, edge = map(int, input().split())
start_vertex = int(input())
graph = {v : [] for v in range(1,vertex+1)}
for _ in range(edge) :
start, end, weight = map(int, input().split())
graph[start].append((end, weight))

heap = []
result = [int(1e9)] * (vertex+1)
result[start_vertex] = 0
heappush(heap, (start_vertex,0))

while heap :

current_node, current_weight = heappop(heap)
if result[current_node] < current_weight :
continue
for node, weight in graph[current_node]:
distance = current_weight + weight
if distance < result[node]:
result[node] = distance
heappush(heap, (node, distance))

for i in range(1,vertex+1):
if result[i] == int(1e9):
print('INF')
else :
print(result[i])


0 comments on commit eb181c3

Please sign in to comment.