From 7da00d110c84c7a8584324bae15146d21d10e732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9D=7CMinseok=20Kim?= Date: Wed, 28 Aug 2024 15:48:05 +0900 Subject: [PATCH] 2024-08-28 solved --- .../\355\214\214\355\213\260.py" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git "a/alstjr7437/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\355\214\214\355\213\260.py" "b/alstjr7437/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\355\214\214\355\213\260.py" index e69de29b..7203c038 100644 --- "a/alstjr7437/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\355\214\214\355\213\260.py" +++ "b/alstjr7437/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\355\214\214\355\213\260.py" @@ -0,0 +1,38 @@ +from collections import deque +import sys + +input = sys.stdin.readline +INF = int(1e9) + +N, M, X = map(int, input().split()) + +graph = [[] for _ in range(N+1)] + +for _ in range(M): + start, target, dist = map(int, input().split()) + graph[start].append((target, dist)) + +def dijkstra(root): + queue = deque() + distance = [INF] * (N + 1) + + distance[root] = 0 + queue.append((root, 0)) + while queue: + now, dist = queue.popleft() + + for target, cost in graph[now]: + target_cost = dist + cost + + if distance[target] > target_cost: + distance[target] = target_cost + queue.append((target, target_cost)) + return distance + +result = [] +for i in range(1, N+1): + go = dijkstra(i)[X] + back = dijkstra(X)[i] + result.append(go+back) + +print(max(result)) \ No newline at end of file