結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-23 21:02:17 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 305 ms / 5,000 ms |
| コード長 | 984 bytes |
| コンパイル時間 | 91 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 13,568 KB |
| 最終ジャッジ日時 | 2024-07-20 16:43:08 |
| 合計ジャッジ時間 | 3,598 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
from collections import deque
N = int(input())
C = int(input())
V = int(input())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
Y = list(map(int, input().split()))
M = list(map(int, input().split()))
edges = [[] for _ in range(N)]
for fr, to, cost, time in zip(S, T, Y, M):
fr -= 1
to -= 1
edges[fr].append((to, cost, time))
que = deque([(0, 0, 0)])
minDist = [(float('inf'), float('inf'))] * N
ans = float('inf')
while que:
now, cost, time = que.popleft()
if minDist[now][0] <= cost and minDist[now][1] <= time:
continue
elif minDist[now][0] > cost and minDist[now][1] > time:
minDist[now] = (cost, time)
if now == N - 1:
ans = min(ans, time)
continue
for to, c, t in edges[now]:
if c + cost > C or (minDist[to][0] <= cost and minDist[to][1] <= time):
continue
que.append((to, c + cost, time + t))
if ans == float('inf'):
print(-1)
else:
print(ans)