diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index eef1313..1739d15 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -86,4 +86,5 @@ | 77차시 | 2024.09.27 | 구현 | 표 병합 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/247 | 78차시 | 2024.10.06 | 그리디 | 풍선 터뜨리기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/250 | 79차시 | 2024.10.12 | 이분 매칭 | 책 나눠주기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/251 +| 80차시 | 2024.11.11 | 다익스트라 | 최소비용 구하기 2 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/254 --- diff --git "a/tgyuuAn/\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\260 2.py" "b/tgyuuAn/\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\260 2.py" new file mode 100644 index 0000000..c575fba --- /dev/null +++ "b/tgyuuAn/\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\260 2.py" @@ -0,0 +1,44 @@ +from heapq import * +from collections import defaultdict +import sys + +def input(): return sys.stdin.readline().rstrip() + +N = int(input()) +M = int(input()) +bus_info = defaultdict(lambda : defaultdict(lambda : int(1e9))) + +for _ in range(M): + n1, n2, cost = map(int,input().split()) + + if bus_info[n1][n2] > cost: + bus_info[n1][n2] = cost + +start, destination = map(int, input().split()) +heap = [] +heappush(heap, [0, 0, start]) + +previous = [1 for _ in range(N+1)] +cost = [int(1e9) for _ in range(N+1)] +while heap: + now_cost, previous_node, now_node = heappop(heap) + + if cost[now_node] <= now_cost: continue + previous[now_node] = previous_node + cost[now_node] = now_cost + + for node in bus_info[now_node]: + temp = now_cost + bus_info[now_node][node] + if cost[node] > temp: + heappush(heap, [temp, now_node, node]) + +print(cost[destination]) + +history = [] +now_history = destination +while now_history != 0: + history.append(now_history) + now_history = previous[now_history] + +print(len(history)) +print(" ".join(map(str, history[-1::-1]))) \ No newline at end of file