結果

問題 No.848 なかよし旅行
ユーザー convexineqconvexineq
提出日時 2019-07-05 22:44:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,181 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 58,164 KB
最終ジャッジ日時 2024-04-16 07:54:09
合計ジャッジ時間 6,628 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

# coding: utf-8
# Your code here!
from heapq import heappush, heappop
def dijkstra(g,start):
    dist = [1e18]*(len(g)) #startからの最短距離
    dist[start] = 0
    q = [(0,start)] #(そこまでの距離、点)
    pending = len(g)-1 #未確定の点の個数
    while q and pending:
        c,v = heappop(q)
        if dist[v] < c: continue
        pending -= 1
        for to, cost in g[v]:
            if dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(q, (dist[to], to))
    return dist

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m,p,q,t = [int(i) for i in readline().split()]
p-=1
q-=1

g = [[] for _ in range(n)]
for i in range(m):
    a,b,c = [int(i) for i in readline().split()]
    g[a-1].append((b-1,c))
    g[b-1].append((a-1,c))

dist0 = dijkstra(g,0)
distp = dijkstra(g,p)
distq = dijkstra(g,q)

ans = -1
for i in range(n):
    for j in range(n):
        m= max(distp[i]+distp[j], distq[i]+distq[j])
        if dist0[i] + dist0[j] + m > t: continue
        ans = max(ans, t-m)

if dist0[p] + distp[q] + dist0[q] < t: ans = t

print(ans)










0