ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 1238 |
문제명 | 파티 |
레벨 | 골드 3 |
분류 |
다익스트라 |
시간복잡도 | O(ElogV) |
인풋사이즈 | V<=1000, E<=10000 |
사용한 언어 | Python |
제출기록 | 34796KB / 108ms |
최고기록 | 72ms |
해결날짜 | 2022/09/20 |
"""Solution code for "BOJ 1238. 파티".
- Problem link: https://www.acmicpc.net/problem/1238
- Solution link: http://www.teferi.net/ps/problems/boj/1238
Tags: [Dijkstra]
"""
import sys
from teflib import graph as tgraph
def main():
N, M, X = [int(x) for x in sys.stdin.readline().split()]
wgraph = [{} for _ in range(N)]
rev_wgraph = [{} for _ in range(N)]
for _ in range(M):
s, e, T = [int(x) for x in sys.stdin.readline().split()]
wgraph[s - 1][e - 1] = rev_wgraph[e - 1][s - 1] = T
times_from_home = tgraph.dijkstra(wgraph, X - 1)
times_to_home = tgraph.dijkstra(rev_wgraph, X - 1)
answer = max(x + y for x, y in zip(times_from_home, times_to_home))
print(answer)
if __name__ == '__main__':
main()