結果

問題 No.848 なかよし旅行
ユーザー lloyzlloyz
提出日時 2024-01-10 00:01:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 539 ms / 2,000 ms
コード長 1,375 bytes
コンパイル時間 2,633 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 97,880 KB
最終ジャッジ日時 2024-01-10 00:01:48
合計ジャッジ時間 8,464 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 539 ms
97,880 KB
testcase_01 AC 53 ms
63,592 KB
testcase_02 AC 42 ms
55,600 KB
testcase_03 AC 43 ms
55,600 KB
testcase_04 AC 43 ms
55,600 KB
testcase_05 AC 44 ms
55,600 KB
testcase_06 AC 60 ms
66,100 KB
testcase_07 AC 50 ms
61,528 KB
testcase_08 AC 91 ms
76,420 KB
testcase_09 AC 116 ms
77,576 KB
testcase_10 AC 100 ms
76,544 KB
testcase_11 AC 249 ms
80,580 KB
testcase_12 AC 308 ms
81,984 KB
testcase_13 AC 308 ms
82,440 KB
testcase_14 AC 228 ms
79,468 KB
testcase_15 AC 300 ms
82,964 KB
testcase_16 AC 412 ms
87,944 KB
testcase_17 AC 307 ms
83,640 KB
testcase_18 AC 246 ms
80,352 KB
testcase_19 AC 248 ms
80,084 KB
testcase_20 AC 225 ms
78,200 KB
testcase_21 AC 328 ms
85,308 KB
testcase_22 AC 244 ms
87,176 KB
testcase_23 AC 196 ms
77,940 KB
testcase_24 AC 42 ms
55,600 KB
testcase_25 AC 416 ms
87,944 KB
testcase_26 AC 42 ms
55,600 KB
testcase_27 AC 41 ms
55,600 KB
testcase_28 AC 41 ms
55,600 KB
testcase_29 AC 42 ms
55,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heappop, heappush

n, m, p, q, t = map(int, input().split())
p -= 1
q -= 1
G = defaultdict(list)
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append((b, c))
    G[b].append((a, c))

INF = 10**18
C0 = [INF for _ in range(n)]
Cp = [INF for _ in range(n)]
Cq = [INF for _ in range(n)]
C0[0] = 0
Cp[p] = 0
Cq[q] = 0
H = [(0, 0)]
while H:
    cc, cp = heappop(H)
    if cc > Cp[cp]:
        continue
    for np, dc in G[cp]:
        nc = cc + dc
        if nc >= C0[np]:
            continue
        C0[np] = nc
        heappush(H, (nc, np))
H = [(0, p)]
while H:
    cc, cp = heappop(H)
    if cc > Cp[cp]:
        continue
    for np, dc in G[cp]:
        nc = cc + dc
        if nc >= Cp[np]:
            continue
        Cp[np] = nc
        heappush(H, (nc, np))
H = [(0, q)]
while H:
    cc, cp = heappop(H)
    if cc > Cq[cp]:
        continue
    for np, dc in G[cp]:
        nc = cc + dc
        if nc >= Cq[np]:
            continue
        Cq[np] = nc
        heappush(H, (nc, np))

ans = -1
if C0[p] + Cp[q] + Cq[0] <= t:
    ans = t
for i in range(n):
    for j in range(n):
        tt = C0[i] + max(Cp[i] + Cp[j], Cq[i] + Cq[j]) + C0[j]
        if tt > t:
            continue
        res = max(Cp[i] + Cp[j], Cq[i] + Cq[j])
        ans = max(ans, t - res)
print(ans)
0