From 98a2dc19da1ce7f76e5ba3012b734cb75de15540 Mon Sep 17 00:00:00 2001 From: seongwon030 <105052068+seongwon030@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:07:37 +0900 Subject: [PATCH] =?UTF-8?q?2024-08-22=2011779=20=EC=B5=9C=EC=86=8C?= =?UTF-8?q?=EB=B9=84=EC=9A=A9=20=EA=B5=AC=ED=95=98=EA=B8=B02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \352\265\254\355\225\230\352\270\2602.py" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "seongwon030/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\2602.py" diff --git "a/seongwon030/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\2602.py" "b/seongwon030/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\2602.py" new file mode 100644 index 0000000..507d6e6 --- /dev/null +++ "b/seongwon030/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\2602.py" @@ -0,0 +1,51 @@ +import sys +import heapq +from collections import defaultdict + +input = sys.stdin.readline + +INF = int(1e9) +n = int(input()) +m = int(input()) +graph = defaultdict(list) + +# 입력 +for _ in range(m): + a,b,c = map(int,input().split()) + graph[a].append((b,c)) + +v1,v2 = map(int,input().split()) + +distance = [INF] * (n+1) +prev_node = [0] * (n+1) +# 데이크 스트라 알고리즘 +def di(start): + q = [] + heapq.heappush(q, [0,start]) + distance[start] = 0 + + while q: + dist, node = heapq.heappop(q) + + if distance[node] < dist: + continue + for n,w in graph[node]: + cost = dist + w + + if distance[n] > cost: + distance[n]= cost + prev_node[n] = node + heapq.heappush(q,[cost,n]) + +di(v1) +print(distance[v2]) + +path = [v2] +now = v2 +while now != v1: + now = prev_node[now] + path.append(now) + +path.reverse() +print(len(path)) +print(' '.join(map(str,path))) \ No newline at end of file