結果

問題 No.848 なかよし旅行
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-05-22 14:01:48
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 959 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 107,620 KB
最終ジャッジ日時 2023-10-20 17:00:09
合計ジャッジ時間 9,112 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 457 ms
107,620 KB
testcase_01 AC 42 ms
55,716 KB
testcase_02 AC 39 ms
53,668 KB
testcase_03 AC 39 ms
53,668 KB
testcase_04 AC 40 ms
53,668 KB
testcase_05 AC 40 ms
53,668 KB
testcase_06 AC 56 ms
64,100 KB
testcase_07 AC 39 ms
53,668 KB
testcase_08 AC 92 ms
76,388 KB
testcase_09 AC 112 ms
76,980 KB
testcase_10 AC 92 ms
76,328 KB
testcase_11 AC 300 ms
84,408 KB
testcase_12 AC 333 ms
86,764 KB
testcase_13 AC 369 ms
88,828 KB
testcase_14 AC 277 ms
80,472 KB
testcase_15 AC 360 ms
89,180 KB
testcase_16 AC 464 ms
99,388 KB
testcase_17 AC 360 ms
91,460 KB
testcase_18 AC 295 ms
82,876 KB
testcase_19 AC 306 ms
82,676 KB
testcase_20 AC 229 ms
78,196 KB
testcase_21 AC 390 ms
94,964 KB
testcase_22 AC 280 ms
97,768 KB
testcase_23 AC 214 ms
77,792 KB
testcase_24 AC 38 ms
53,668 KB
testcase_25 AC 469 ms
99,488 KB
testcase_26 AC 38 ms
53,668 KB
testcase_27 AC 39 ms
53,668 KB
testcase_28 AC 39 ms
53,668 KB
testcase_29 AC 38 ms
53,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush,heappop

n,m,p,q,t = map(int,input().split())
e = [[] for i in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    e[a].append([b,c])
    e[b].append([a,c])

p,q = p-1,q-1

inf = 10**20
mod = 1<<16
def dijkstra(x):
    dis = [inf]*n
    dis[x] = 0
    h = [x]
    while h:
        d,now = divmod(heappop(h),mod)
        if dis[now] != d:
            continue
        for nex,c in e[now]:
            if dis[nex] > d+c:
                dis[nex] = d+c
                heappush(h,((d+c)<<16)+nex)
    return dis


dis0 = dijkstra(0)
disp = dijkstra(p)
disq = dijkstra(q)
ans = -1

if dis0[p]+dis0[q]+disp[q] <= t:
    print(t)
    exit()
    
for i in range(n):
    for j in range(n):
        t1 = dis0[i]
        t2 = dis0[j]
        
        t3 = max(disp[i]+disp[j],disq[i]+disq[j])

        if t1+t2+t3 > t:
            continue
        ans = max(ans,t-t3)
if ans == inf:
    ans = -1
print(ans)
0