結果

問題 No.848 なかよし旅行
ユーザー convexineqconvexineq
提出日時 2019-07-05 22:47:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 487 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 87,356 KB
実行使用メモリ 105,944 KB
最終ジャッジ日時 2023-08-07 19:42:53
合計ジャッジ時間 8,516 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 487 ms
105,944 KB
testcase_01 AC 86 ms
76,120 KB
testcase_02 AC 77 ms
71,272 KB
testcase_03 AC 78 ms
71,368 KB
testcase_04 AC 80 ms
71,376 KB
testcase_05 AC 78 ms
71,564 KB
testcase_06 AC 95 ms
76,684 KB
testcase_07 AC 82 ms
75,984 KB
testcase_08 AC 120 ms
77,976 KB
testcase_09 AC 144 ms
78,724 KB
testcase_10 AC 121 ms
78,040 KB
testcase_11 AC 304 ms
83,160 KB
testcase_12 AC 336 ms
84,352 KB
testcase_13 AC 342 ms
85,504 KB
testcase_14 AC 290 ms
82,264 KB
testcase_15 AC 334 ms
86,180 KB
testcase_16 AC 415 ms
91,444 KB
testcase_17 AC 326 ms
87,280 KB
testcase_18 AC 292 ms
83,276 KB
testcase_19 AC 295 ms
82,404 KB
testcase_20 AC 243 ms
79,816 KB
testcase_21 AC 355 ms
88,948 KB
testcase_22 AC 247 ms
90,236 KB
testcase_23 AC 218 ms
79,124 KB
testcase_24 AC 79 ms
71,504 KB
testcase_25 AC 425 ms
91,716 KB
testcase_26 AC 78 ms
71,176 KB
testcase_27 AC 77 ms
71,528 KB
testcase_28 AC 76 ms
71,532 KB
testcase_29 AC 78 ms
71,432 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