結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
terasa
|
| 提出日時 | 2022-06-01 21:52:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 112 ms / 5,000 ms |
| コード長 | 1,000 bytes |
| コンパイル時間 | 255 ms |
| コンパイル使用メモリ | 82,308 KB |
| 実行使用メモリ | 77,952 KB |
| 最終ジャッジ日時 | 2024-09-21 01:44:22 |
| 合計ジャッジ時間 | 4,648 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')
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()))
INF = 1 << 30
E = [[] for _ in range(N + 1)]
for s, t, y, m in zip(S, T, Y, M):
E[s].append((t, y, m))
# dp[i][j] := 町iに総コストjかけて辿り着ける最小の時間
dp = [[INF for _ in range(C + 1)] for _ in range(N + 1)]
dp[1][0] = 0
h = [(0, 1, 0)]
while len(h) > 0:
_, v, c = heapq.heappop(h)
for d, y, m in E[v]:
if c + y > C:
continue
if dp[d][c + y] > dp[v][c] + m:
dp[d][c + y] = dp[v][c] + m
heapq.heappush(h, (dp[d][c + y], d, c + y))
ans = min(dp[N])
print(ans if ans < INF else -1)
terasa