結果

問題 No.848 なかよし旅行
ユーザー tpynerivertpyneriver
提出日時 2019-07-05 22:11:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 601 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 102,624 KB
最終ジャッジ日時 2024-04-25 13:49:21
合計ジャッジ時間 7,507 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 372 ms
101,024 KB
testcase_01 AC 48 ms
60,704 KB
testcase_02 AC 38 ms
53,260 KB
testcase_03 AC 39 ms
54,424 KB
testcase_04 AC 39 ms
55,008 KB
testcase_05 AC 38 ms
53,448 KB
testcase_06 AC 60 ms
68,184 KB
testcase_07 AC 43 ms
60,504 KB
testcase_08 AC 89 ms
76,384 KB
testcase_09 AC 122 ms
77,596 KB
testcase_10 AC 101 ms
76,752 KB
testcase_11 AC 276 ms
84,100 KB
testcase_12 AC 302 ms
86,980 KB
testcase_13 AC 348 ms
89,412 KB
testcase_14 AC 229 ms
79,572 KB
testcase_15 AC 349 ms
89,604 KB
testcase_16 AC 458 ms
102,624 KB
testcase_17 AC 339 ms
91,320 KB
testcase_18 AC 261 ms
83,044 KB
testcase_19 AC 250 ms
81,544 KB
testcase_20 AC 192 ms
78,116 KB
testcase_21 AC 364 ms
95,776 KB
testcase_22 AC 298 ms
100,352 KB
testcase_23 AC 167 ms
76,836 KB
testcase_24 AC 38 ms
52,808 KB
testcase_25 AC 601 ms
97,688 KB
testcase_26 AC 37 ms
53,140 KB
testcase_27 AC 39 ms
53,620 KB
testcase_28 AC 37 ms
53,112 KB
testcase_29 AC 38 ms
53,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappop as hpp, heappush as hp
def dijkstra(N, s, Edge):
    inf = 10**10
    dist = [inf] * N
    Q = [(0, s)]
    decided = set()
    for _ in range(N):
        while True:
            dn, vn = hpp(Q)
            if vn not in decided:
                decided.add(vn)
                dist[vn] = dn
                break
        for vf, df in Edge[vn]:
            if vf not in decided:
                hp(Q, (dn + df, vf))
    return dist


N, M, P, Q, T = map(int, input().split())
P -= 1
Q -= 1
Edge = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    Edge[a].append((b, c))
    Edge[b].append((a, c))

dist0 = dijkstra(N, 0, Edge)
distP = dijkstra(N, P, Edge)
distQ = dijkstra(N, Q, Edge)


ans = -1
for i in range(N):
    for j in range(N):
        t = dist0[i] + dist0[j] + max(distP[i]+distP[j], distQ[i]+distQ[j])
        if t > T:
            continue

        ans = max(ans, dist0[i] + dist0[j] + T - t)
if dist0[P] + distP[Q] + dist0[Q] <= T:
    ans = T
print(ans)        
0