結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-22 14:01:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 475 ms / 2,000 ms |
| コード長 | 959 bytes |
| コンパイル時間 | 219 ms |
| コンパイル使用メモリ | 82,736 KB |
| 実行使用メモリ | 107,900 KB |
| 最終ジャッジ日時 | 2024-09-20 12:34:33 |
| 合計ジャッジ時間 | 8,496 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
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)