結果

問題 No.848 なかよし旅行
ユーザー mkawa2mkawa2
提出日時 2021-03-16 16:26:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,455 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 51,540 KB
最終ジャッジ日時 2024-04-25 15:05:21
合計ジャッジ時間 9,592 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,100 ms
51,540 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 29 ms
10,880 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 29 ms
11,008 KB
testcase_05 AC 29 ms
11,008 KB
testcase_06 AC 32 ms
11,136 KB
testcase_07 AC 29 ms
11,008 KB
testcase_08 AC 87 ms
11,008 KB
testcase_09 AC 85 ms
11,392 KB
testcase_10 AC 87 ms
11,008 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
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 #

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