From eb181c30f9199fbd45f2c40b453efc8138d2604d Mon Sep 17 00:00:00 2001 From: JangHongJoon Date: Wed, 27 Mar 2024 16:33:07 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ACM-1753.py" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-1753.py" diff --git "a/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-1753.py" "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-1753.py" new file mode 100644 index 0000000..9fd3d4e --- /dev/null +++ "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-1753.py" @@ -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]) + +