結果

問題 No.848 なかよし旅行
コンテスト
ユーザー ああ
提出日時 2026-05-18 18:32:22
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 336 ms / 2,000 ms
コード長 775 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 143 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 106,596 KB
最終ジャッジ日時 2026-05-18 18:32:35
合計ジャッジ時間 5,793 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq

def aa(m):
    global n
    hq=[];heapq.heappush(hq,(0,m))
    res=[1<<60]*n;res[m]=0
    while hq:
        q,w=heapq.heappop(hq)
        if res[w]<q:
            continue
        for i,j in v[w]:
            if res[i]>q+j:
                res[i]=q+j
                heapq.heappush(hq,(res[i],i))
    return res

n,m,p,q,t=map(int,input().split());q-=1;p-=1
v=[[] for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split());a-=1;b-=1
    v[a].append((b,c));v[b].append((a,c))
x,y,z=aa(0),aa(p),aa(q)
if max(x[q]*2,x[p]*2)>t:
    print(-1);exit()
if x[q]+x[p]+y[q]<=t:
    print(t);exit()
ans=0
for i in range(n):
    for j in range(n):
        if max(y[i]+y[j],z[i]+z[j])+x[i]+x[j]<=t:
            ans=max(ans,t-max(y[i]+y[j],z[i]+z[j]))
print(ans)
0