結果

問題 No.848 なかよし旅行
ユーザー 👑 rin204rin204
提出日時 2022-07-14 13:08:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 97,764 KB
最終ジャッジ日時 2023-09-08 03:07:17
合計ジャッジ時間 9,313 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 447 ms
97,764 KB
testcase_01 AC 77 ms
71,516 KB
testcase_02 AC 72 ms
71,340 KB
testcase_03 AC 74 ms
71,380 KB
testcase_04 AC 74 ms
71,312 KB
testcase_05 AC 76 ms
71,444 KB
testcase_06 AC 89 ms
76,160 KB
testcase_07 AC 76 ms
71,228 KB
testcase_08 AC 123 ms
77,932 KB
testcase_09 AC 147 ms
79,040 KB
testcase_10 AC 125 ms
77,888 KB
testcase_11 AC 290 ms
82,152 KB
testcase_12 AC 311 ms
82,776 KB
testcase_13 AC 339 ms
83,828 KB
testcase_14 AC 265 ms
80,812 KB
testcase_15 AC 339 ms
84,156 KB
testcase_16 AC 420 ms
89,512 KB
testcase_17 AC 336 ms
84,984 KB
testcase_18 AC 279 ms
81,764 KB
testcase_19 AC 297 ms
82,180 KB
testcase_20 AC 173 ms
78,972 KB
testcase_21 AC 359 ms
87,024 KB
testcase_22 AC 287 ms
89,124 KB
testcase_23 AC 224 ms
78,904 KB
testcase_24 AC 75 ms
71,580 KB
testcase_25 AC 405 ms
88,940 KB
testcase_26 AC 74 ms
71,244 KB
testcase_27 AC 77 ms
71,460 KB
testcase_28 AC 78 ms
71,280 KB
testcase_29 AC 75 ms
71,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, m, p, q, t = map(int, input().split())
p -= 1
q -= 1
edges = [[] for _ in range(n)]
for _ in range(m):
    u, v, c = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append((v, c))
    edges[v].append((u, c))

def dijkstra(s):
    inf = 1 << 60
    dist = [inf] * n
    dist[s] = 0
    hq = [s]
    while hq:
        tmp = heappop(hq)
        d = tmp // n
        pos = tmp - d * n
        if dist[pos] < d:
            continue
        for npos, c in edges[pos]:
            tmp = c + d
            if dist[npos] > tmp:
                dist[npos] = tmp
                heappush(hq, (tmp * n + npos))
    return dist

d0 = dijkstra(0)
dp = dijkstra(p)
dq = dijkstra(q)

if d0[p] + dp[q] + dq[0] <= t:
    print(t)
elif max(d0[p] * 2, d0[q] * 2) > t:
    print(-1)
else:
    ans = 0
    for i in range(n):
        for j in range(n):
            d = d0[i] + d0[j]
            d1 = max(dp[i] + dp[j], dq[i] + dq[j])
            if d + d1 <= t:
                ans = max(ans, t - d1)
    print(ans)


0