結果

問題 No.848 なかよし旅行
ユーザー mkawa2mkawa2
提出日時 2019-07-06 07:26:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 871 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 94,904 KB
最終ジャッジ日時 2024-04-16 08:22:18
合計ジャッジ時間 6,700 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
n,m,p,q,t=map(int,input().split())
to={}
for _ in range(m):
    a,b,c=map(int,input().split())
    to.setdefault(a,[])
    to.setdefault(b, [])
    to[a].append([b,c])
    to[b].append([a,c])

sy=[[-1]*(n+1) for _ in range(n+1)]
for s in range(1,n+1):
    hp = []
    heappush(hp, [0, s])
    syr=sy[s]
    while hp:
        ji, g = heappop(hp)
        if syr[g] != -1: continue
        syr[g] = ji
        for ng, dt in to[g]:
            if syr[ng] != -1: continue
            heappush(hp, [ji + dt, ng])


if sy[1][p]+sy[1][q]+sy[p][q]<=t:
    print(t)
elif sy[1][p]*2>t or sy[1][q]*2>t:
    print(-1)
else:
    mn=t
    for w in range(1,n+1):
        if w in [p,q]:continue
        for a in range(1,n+1):
            mx=max(sy[w][p]+sy[p][a],sy[w][q]+sy[q][a])
            if sy[1][w]+mx+sy[a][1]<=t:
                mn=min(mn,mx)
    print(t-mn)
0