結果

問題 No.848 なかよし旅行
ユーザー mkawa2mkawa2
提出日時 2019-07-06 07:43:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,275 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 56,096 KB
最終ジャッジ日時 2024-04-16 08:25:34
合計ジャッジ時間 17,297 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,099 ms
56,096 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 35 ms
11,008 KB
testcase_07 AC 32 ms
10,752 KB
testcase_08 AC 74 ms
11,008 KB
testcase_09 AC 73 ms
11,136 KB
testcase_10 AC 73 ms
11,008 KB
testcase_11 AC 1,703 ms
22,016 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 1,963 ms
14,848 KB
testcase_15 TLE -
testcase_16 TLE -
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 *
import sys
input=sys.stdin.readline

def f(n,m,p,q,t):
    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(3)]
    for i,s in enumerate([1,p,q]):
        hp = []
        heappush(hp, [0, s])
        syr = sy[i]
        cnt=0
        while cnt<n:
            ji, g = heappop(hp)
            if syr[g] != -1: continue
            syr[g] = ji
            cnt+=1
            for ng, dt in to[g]:
                if syr[ng] != -1: continue
                heappush(hp, [ji + dt, ng])

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

n,m,p,q,t=map(int,input().split())
f(n,m,p,q,t)
0