結果

問題 No.1 道のショートカット
ユーザー terasaterasa
提出日時 2022-06-01 21:52:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 114 ms / 5,000 ms
コード長 1,000 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 81,724 KB
実行使用メモリ 77,572 KB
最終ジャッジ日時 2023-10-21 00:58:02
合計ジャッジ時間 4,547 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,616 KB
testcase_01 AC 44 ms
55,616 KB
testcase_02 AC 44 ms
55,616 KB
testcase_03 AC 44 ms
55,616 KB
testcase_04 AC 44 ms
55,616 KB
testcase_05 AC 45 ms
55,616 KB
testcase_06 AC 46 ms
55,616 KB
testcase_07 AC 45 ms
55,616 KB
testcase_08 AC 93 ms
77,076 KB
testcase_09 AC 68 ms
70,704 KB
testcase_10 AC 87 ms
76,456 KB
testcase_11 AC 93 ms
77,084 KB
testcase_12 AC 114 ms
77,572 KB
testcase_13 AC 112 ms
77,444 KB
testcase_14 AC 49 ms
61,084 KB
testcase_15 AC 47 ms
61,084 KB
testcase_16 AC 53 ms
64,116 KB
testcase_17 AC 47 ms
61,084 KB
testcase_18 AC 49 ms
61,084 KB
testcase_19 AC 49 ms
61,084 KB
testcase_20 AC 85 ms
76,704 KB
testcase_21 AC 61 ms
66,348 KB
testcase_22 AC 50 ms
61,084 KB
testcase_23 AC 107 ms
77,144 KB
testcase_24 AC 107 ms
77,092 KB
testcase_25 AC 89 ms
76,732 KB
testcase_26 AC 73 ms
72,616 KB
testcase_27 AC 105 ms
77,116 KB
testcase_28 AC 46 ms
61,084 KB
testcase_29 AC 75 ms
73,616 KB
testcase_30 AC 55 ms
64,412 KB
testcase_31 AC 63 ms
68,512 KB
testcase_32 AC 86 ms
76,900 KB
testcase_33 AC 74 ms
73,636 KB
testcase_34 AC 94 ms
77,032 KB
testcase_35 AC 49 ms
61,552 KB
testcase_36 AC 71 ms
70,704 KB
testcase_37 AC 53 ms
64,128 KB
testcase_38 AC 48 ms
61,084 KB
testcase_39 AC 49 ms
61,084 KB
testcase_40 AC 54 ms
64,120 KB
testcase_41 AC 47 ms
55,616 KB
testcase_42 AC 46 ms
55,616 KB
testcase_43 AC 48 ms
61,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0