結果
問題 |
No.848 なかよし旅行
|
ユーザー |
![]() |
提出日時 | 2019-07-06 07:34:45 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,170 bytes |
コンパイル時間 | 104 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 87,704 KB |
最終ジャッジ日時 | 2024-10-06 23:39:42 |
合計ジャッジ時間 | 13,948 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | AC * 13 TLE * 4 -- * 9 |
ソースコード
from heapq import * def f(n,m,p,q,t): to = {} for _ in range(m): a, b, c = map(int, input().split()) to.setdefault(a, []) to.setdefault(b, []) to[a].append([b, c]) to[b].append([a, c]) sy = [[-1] * (n + 1) for _ in range(n + 1)] for s in [1,p,q]: hp = [] heappush(hp, [0, s]) syr = sy[s] while hp: ji, g = heappop(hp) if syr[g] != -1: continue syr[g] = ji for ng, dt in to[g]: if syr[ng] != -1: continue heappush(hp, [ji + dt, ng]) if sy[1][p] + sy[1][q] + sy[p][q] <= t: print(t) elif sy[1][p] * 2 > t or sy[1][q] * 2 > t: print(-1) else: mn = t syp=sy[p] syq=sy[q] sy1=sy[1] for w in range(1, n + 1): if w in [p, q]: continue for a in range(1, n + 1): if a in [p, q]: continue mx = max(syp[w] + syp[a], syq[w] + syq[a]) if sy1[w] + mx + sy1[a] <= t: mn = min(mn, mx) print(t - mn) n,m,p,q,t=map(int,input().split()) f(n,m,p,q,t)