結果
| 問題 |
No.2387 Yokan Factory
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-21 21:27:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,997 ms / 5,000 ms |
| コード長 | 1,433 bytes |
| コンパイル時間 | 215 ms |
| コンパイル使用メモリ | 82,344 KB |
| 実行使用メモリ | 279,820 KB |
| 最終ジャッジ日時 | 2024-09-21 22:42:59 |
| 合計ジャッジ時間 | 27,639 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
def Dijkstra(s, graph):
INF = 2 ** 63 - 1
import heapq
n = len(graph)
dist = [INF] * n
dist[s] = 0
bef = [0] * n
bef[s] = s
hq = [(0, s)]
heapq.heapify(hq)
while hq:
c, now = heapq.heappop(hq)
if c > dist[now]:
continue
for to, cost in graph[now]:
if dist[now] + cost < dist[to]:
dist[to] = cost + dist[now]
bef[to] = now
heapq.heappush(hq, (dist[to], + to))
return dist, bef
def DijkstraRest(bef, t):
now = t
ret = []
while bef[now] != now:
ret.append((bef[now], now))
now = bef[now]
ret.reverse()
return ret
n, m, x = mi()
ABCD = [li() for _ in range(m)]
def check(l):
graph = [[] for _ in range(n + 1)]
for a, b, c, d in ABCD:
a -= 1; b -= 1
if d >= l:
graph[a].append((b, c))
graph[b].append((a, c))
d, _ = Dijkstra(0, graph)
if d[n - 1] <= x:
return True
return False
ok = -1
ng = 10 ** 9 + 2
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if check(mid):
ok = mid
else:
ng = mid
print(ok)