목차

파티

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()