結果

問題 No.848 なかよし旅行
ユーザー tpynerivertpyneriver
提出日時 2019-07-05 22:11:48
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 619 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 103,152 KB
最終ジャッジ日時 2023-08-07 19:41:04
合計ジャッジ時間 8,508 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 386 ms
103,152 KB
testcase_01 AC 80 ms
76,056 KB
testcase_02 AC 74 ms
71,324 KB
testcase_03 AC 75 ms
71,380 KB
testcase_04 AC 75 ms
71,540 KB
testcase_05 AC 74 ms
71,560 KB
testcase_06 AC 95 ms
76,636 KB
testcase_07 AC 80 ms
75,828 KB
testcase_08 AC 120 ms
78,180 KB
testcase_09 AC 155 ms
78,488 KB
testcase_10 AC 133 ms
78,516 KB
testcase_11 AC 301 ms
85,188 KB
testcase_12 AC 324 ms
88,300 KB
testcase_13 AC 379 ms
93,288 KB
testcase_14 AC 262 ms
81,996 KB
testcase_15 AC 370 ms
90,924 KB
testcase_16 AC 472 ms
102,868 KB
testcase_17 AC 360 ms
94,104 KB
testcase_18 AC 296 ms
84,680 KB
testcase_19 AC 289 ms
83,348 KB
testcase_20 AC 227 ms
80,024 KB
testcase_21 AC 396 ms
96,976 KB
testcase_22 AC 314 ms
102,736 KB
testcase_23 AC 200 ms
79,268 KB
testcase_24 AC 75 ms
71,356 KB
testcase_25 AC 619 ms
100,300 KB
testcase_26 AC 73 ms
71,380 KB
testcase_27 AC 73 ms
71,444 KB
testcase_28 AC 74 ms
71,596 KB
testcase_29 AC 75 ms
71,592 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