結果

問題 No.848 なかよし旅行
ユーザー ああいいああいい
提出日時 2022-04-20 11:31:41
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 623 ms / 2,000 ms
コード長 1,026 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 105,104 KB
最終ジャッジ日時 2023-09-02 05:22:28
合計ジャッジ時間 10,406 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 623 ms
105,104 KB
testcase_01 AC 85 ms
71,408 KB
testcase_02 AC 80 ms
71,408 KB
testcase_03 AC 81 ms
71,388 KB
testcase_04 AC 84 ms
71,268 KB
testcase_05 AC 83 ms
71,412 KB
testcase_06 AC 98 ms
76,232 KB
testcase_07 AC 84 ms
71,260 KB
testcase_08 AC 141 ms
78,928 KB
testcase_09 AC 161 ms
79,092 KB
testcase_10 AC 139 ms
77,696 KB
testcase_11 AC 270 ms
81,996 KB
testcase_12 AC 298 ms
82,672 KB
testcase_13 AC 309 ms
84,632 KB
testcase_14 AC 252 ms
81,044 KB
testcase_15 AC 316 ms
84,872 KB
testcase_16 AC 381 ms
88,856 KB
testcase_17 AC 340 ms
85,516 KB
testcase_18 AC 289 ms
82,056 KB
testcase_19 AC 272 ms
81,036 KB
testcase_20 AC 226 ms
78,940 KB
testcase_21 AC 339 ms
86,652 KB
testcase_22 AC 293 ms
88,196 KB
testcase_23 AC 191 ms
79,504 KB
testcase_24 AC 79 ms
71,548 KB
testcase_25 AC 394 ms
89,316 KB
testcase_26 AC 84 ms
71,556 KB
testcase_27 AC 84 ms
71,340 KB
testcase_28 AC 82 ms
71,396 KB
testcase_29 AC 80 ms
71,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,P,Q,T = map(int,input().split())
P -= 1
Q -= 1
G = [[] for _ in range(N)]
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 ** 9 * 2000 + 1000
dist = [[inf] * N for _ in range(3)]
from heapq import heappop,heappush
for i in range(3):
    if i == 0:
        s = 0
    elif i == 1:
        s = P
    else:
        s = Q
    q = [(0,s)]
    dist[i][s] = 0
    while q:
        d,now = heappop(q)
        if dist[i][now] < d:continue
        for v,c in G[now]:
            if dist[i][v] > d + c:
                dist[i][v] = d + c
                heappush(q,(d + c,v))

import sys
t = dist[0][P] + dist[1][Q] + dist[0][Q]
if t <= T:
    print(T)
    exit()
ans = -1


for u in range(N):
    for v in range(u,N):
        t = max(dist[1][u] + dist[1][v],dist[2][u] + dist[2][v])
        tmp = dist[0][u] + t + dist[0][v]
        if tmp > T:continue
        #t = dist[0][u] + dist[0][v]
        if T - t > ans:
            ans = T - t
print(ans)
0