結果

問題 No.848 なかよし旅行
ユーザー convexineqconvexineq
提出日時 2019-07-05 22:47:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 103,740 KB
最終ジャッジ日時 2024-04-25 13:50:56
合計ジャッジ時間 6,073 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 379 ms
103,740 KB
testcase_01 AC 45 ms
60,748 KB
testcase_02 AC 37 ms
53,912 KB
testcase_03 AC 38 ms
53,168 KB
testcase_04 AC 38 ms
54,544 KB
testcase_05 AC 37 ms
54,004 KB
testcase_06 AC 52 ms
65,572 KB
testcase_07 AC 41 ms
60,116 KB
testcase_08 AC 80 ms
76,924 KB
testcase_09 AC 100 ms
77,088 KB
testcase_10 AC 82 ms
77,004 KB
testcase_11 AC 246 ms
81,516 KB
testcase_12 AC 273 ms
82,552 KB
testcase_13 AC 266 ms
84,508 KB
testcase_14 AC 224 ms
79,284 KB
testcase_15 AC 260 ms
83,896 KB
testcase_16 AC 326 ms
90,480 KB
testcase_17 AC 244 ms
84,904 KB
testcase_18 AC 220 ms
81,084 KB
testcase_19 AC 231 ms
80,436 KB
testcase_20 AC 188 ms
78,148 KB
testcase_21 AC 270 ms
86,944 KB
testcase_22 AC 173 ms
88,668 KB
testcase_23 AC 171 ms
77,476 KB
testcase_24 AC 36 ms
53,344 KB
testcase_25 AC 336 ms
89,916 KB
testcase_26 AC 37 ms
53,308 KB
testcase_27 AC 39 ms
52,532 KB
testcase_28 AC 37 ms
54,128 KB
testcase_29 AC 36 ms
53,016 KB
権限があれば一括ダウンロードができます

ソースコード

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