結果

問題 No.848 なかよし旅行
ユーザー tobusakanatobusakana
提出日時 2022-11-29 00:40:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,402 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 82,956 KB
実行使用メモリ 113,436 KB
最終ジャッジ日時 2024-04-15 22:00:29
合計ジャッジ時間 9,932 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 645 ms
113,032 KB
testcase_01 AC 46 ms
53,632 KB
testcase_02 WA -
testcase_03 AC 44 ms
53,248 KB
testcase_04 AC 44 ms
53,248 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 45 ms
53,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 468 ms
97,264 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 149 ms
78,356 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 44 ms
53,120 KB
testcase_25 WA -
testcase_26 AC 44 ms
52,992 KB
testcase_27 AC 43 ms
52,736 KB
testcase_28 AC 43 ms
52,480 KB
testcase_29 AC 46 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

N,M,P,Q,T = map(int,readline().split())
P -= 1
Q -= 1
G = [[] for i in range(N)]
for _ in range(M):
    a,b,c = map(int,readline().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
INF = 1 << 60
import heapq as hq
def get_dist_from(x):
    dist = [INF] * N
    q = []
    hq.heappush(q, (0, x))
    while q:
        d, v = hq.heappop(q)
        if dist[v] != INF:
            continue
        dist[v] = d
        for child, c in G[v]:
            if dist[child] != INF:
                continue
            hq.heappush(q, (d + c, child))
    return dist
    
dist_from_0 = get_dist_from(0)
dist_from_P = get_dist_from(P)
dist_from_Q = get_dist_from(Q)


if dist_from_0[P] + dist_from_Q[P] + dist_from_0[Q] <= T:
    print(T)
    exit(0)

ans = -1
for v in range(N):
    # vまで一緒に行動して、以後別行動パターン
    time = dist_from_0[v] + max(dist_from_Q[v] + dist_from_Q[0], dist_from_P[v] + dist_from_P[0])
    if time <= T:
        # 一緒にいる時間
        stay = (T - time) + dist_from_0[v]
        ans = max(ans, stay)

    # vまで一緒に行動、P,Qを訪れて、またvに合流するパターン
    time = dist_from_0[v] * 2 + max(dist_from_P[v] * 2, dist_from_Q[v] * 2)
    if time <= T:
        stay = T - max(dist_from_P[v] * 2, dist_from_Q[v] * 2)
        ans = max(ans, stay)
print(ans)
0