結果
| 問題 | No.1 道のショートカット |
| コンテスト | |
| ユーザー |
stnkien
|
| 提出日時 | 2020-06-12 00:56:34 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 159 ms / 5,000 ms |
| コード長 | 766 bytes |
| 記録 | |
| コンパイル時間 | 547 ms |
| コンパイル使用メモリ | 85,504 KB |
| 実行使用メモリ | 139,604 KB |
| 最終ジャッジ日時 | 2026-04-03 01:34:16 |
| 合計ジャッジ時間 | 4,067 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
from heapq import heapify, heappop, heappush
N = int(input())
C = int(input())
V = int(input())
*S, = map(int, input().split())
*T, = map(int, input().split())
*Y, = map(int, input().split())
*M, = map(int, input().split())
G = [[] for _ in [0]*(N+1)]
for s, *t in zip(S, T, Y, M):
G[s].append(t)
INF = 10**10
D = [[INF]*(C+1) for _ in [0]*(N+1)]
used = set()
q = []
heappush(q, (0, 1, C))
while q:
dmin = INF
d, v, c = heappop(q)
if (v, c) in used:
continue
used.add((v, c))
D[v][c] = d
for u, y, m in G[v]:
if (u, c-y) in used or c-y < 0:
continue
new_d = d+m
if new_d < D[u][c-y]:
heappush(q, (d+m, u, c-y))
ans = min(D[N])
if ans == INF:
print(-1)
else:
print(ans)
stnkien