結果
| 問題 | No.848 なかよし旅行 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-18 18:32:22 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 336 ms / 2,000 ms |
| コード長 | 775 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
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)