結果
| 問題 |
No.2387 Yokan Factory
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-21 21:57:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,522 ms / 5,000 ms |
| コード長 | 887 bytes |
| コンパイル時間 | 177 ms |
| コンパイル使用メモリ | 82,576 KB |
| 実行使用メモリ | 144,332 KB |
| 最終ジャッジ日時 | 2024-09-21 23:29:06 |
| 合計ジャッジ時間 | 16,385 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
from heapq import heappop,heappush
n,m,x = map(int,input().split())
size = set()
size.add(1)
e = [[] for i in range(n)]
for _ in range(m):
u,v,a,b = map(int,input().split())
size.add(b)
u,v = u-1,v-1
e[u].append([v,a,b])
e[v].append([u,a,b])
size = sorted(size)
l = 0
r = len(size)
inf = 10**20
mod = 1<<20
def search(s):
dis = [inf]*n
dis[0] = 0
h = [0]
while h:
d,now = divmod(heappop(h),mod)
if dis[now] != d:
continue
for nex,a,b in e[now]:
if b < s:
continue
if dis[nex] > dis[now]+a:
dis[nex] = dis[now]+a
heappush(h,(dis[nex]<<20)+nex)
return dis[-1]
while r > l+1:
m = (r+l)//2
if search(size[m]) <= x:
l = m
else:
r = m
ans = search(size[l])
if ans > x:
print(-1)
else:
print(size[l])