結果

問題 No.848 なかよし旅行
ユーザー mkawa2mkawa2
提出日時 2021-03-16 16:26:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 104,136 KB
最終ジャッジ日時 2024-04-25 15:05:28
合計ジャッジ時間 6,265 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 506 ms
104,136 KB
testcase_01 AC 40 ms
55,980 KB
testcase_02 AC 36 ms
53,944 KB
testcase_03 AC 37 ms
53,628 KB
testcase_04 AC 36 ms
54,644 KB
testcase_05 AC 37 ms
54,984 KB
testcase_06 AC 50 ms
65,172 KB
testcase_07 AC 37 ms
54,304 KB
testcase_08 AC 82 ms
77,004 KB
testcase_09 AC 100 ms
77,580 KB
testcase_10 AC 85 ms
77,036 KB
testcase_11 AC 226 ms
81,088 KB
testcase_12 AC 251 ms
82,396 KB
testcase_13 AC 249 ms
83,756 KB
testcase_14 AC 208 ms
78,956 KB
testcase_15 AC 257 ms
83,392 KB
testcase_16 AC 308 ms
88,472 KB
testcase_17 AC 245 ms
84,040 KB
testcase_18 AC 217 ms
80,520 KB
testcase_19 AC 222 ms
80,804 KB
testcase_20 AC 177 ms
78,236 KB
testcase_21 AC 257 ms
85,376 KB
testcase_22 AC 204 ms
87,276 KB
testcase_23 AC 162 ms
77,560 KB
testcase_24 AC 36 ms
52,944 KB
testcase_25 AC 325 ms
88,256 KB
testcase_26 AC 38 ms
54,928 KB
testcase_27 AC 37 ms
53,336 KB
testcase_28 AC 36 ms
53,140 KB
testcase_29 AC 36 ms
53,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

from heapq import *

n,m,p,q,t=LI()
p,q=p-1,q-1
to=[[] for _ in range(n)]
for _ in range(m):
    u,v,c=LI()
    u,v=u-1,v-1
    to[u].append((v,c))
    to[v].append((u,c))

def dijkstra(u):
    dist=[inf]*n
    dist[u]=0
    hp=[(0,u)]
    while hp:
        d,u=heappop(hp)
        if d>dist[u]:continue
        for v,c in to[u]:
            nd=d+c
            if nd>=dist[v]:continue
            dist[v]=nd
            heappush(hp,(nd,v))
    return dist

to0=dijkstra(0)
top=dijkstra(p)
toq=dijkstra(q)

if to0[p]+to0[q]+top[q]<=t:
    print(t)
    exit()

ans=-inf
for u in range(n):
    for v in range(n):
        mx=max(top[u]+top[v],toq[u]+toq[v])
        if to0[u]+to0[v]+mx>t:continue
        ans=max(ans,t-mx)

if ans==-inf:ans=-1
print(ans)
0