結果

問題 No.1 道のショートカット
ユーザー rlangevinrlangevin
提出日時 2023-11-17 12:30:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 811 ms / 5,000 ms
コード長 1,159 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 84,040 KB
最終ジャッジ日時 2023-11-17 12:30:43
合計ジャッジ時間 6,918 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
59,212 KB
testcase_01 AC 41 ms
59,212 KB
testcase_02 AC 41 ms
59,212 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 41 ms
59,212 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 41 ms
59,196 KB
testcase_08 AC 279 ms
83,012 KB
testcase_09 AC 89 ms
70,748 KB
testcase_10 AC 107 ms
72,860 KB
testcase_11 AC 124 ms
73,868 KB
testcase_12 AC 811 ms
84,040 KB
testcase_13 AC 738 ms
84,040 KB
testcase_14 AC 53 ms
64,048 KB
testcase_15 AC 41 ms
59,204 KB
testcase_16 AC 63 ms
66,636 KB
testcase_17 AC 43 ms
59,876 KB
testcase_18 AC 53 ms
64,044 KB
testcase_19 AC 58 ms
66,120 KB
testcase_20 AC 108 ms
70,808 KB
testcase_21 AC 76 ms
68,440 KB
testcase_22 AC 56 ms
66,124 KB
testcase_23 AC 131 ms
82,244 KB
testcase_24 AC 163 ms
82,896 KB
testcase_25 AC 121 ms
72,856 KB
testcase_26 AC 88 ms
70,540 KB
testcase_27 AC 308 ms
81,860 KB
testcase_28 AC 47 ms
61,960 KB
testcase_29 AC 64 ms
70,800 KB
testcase_30 AC 51 ms
64,576 KB
testcase_31 AC 57 ms
68,732 KB
testcase_32 AC 234 ms
80,996 KB
testcase_33 AC 122 ms
74,136 KB
testcase_34 AC 156 ms
81,096 KB
testcase_35 AC 45 ms
62,348 KB
testcase_36 AC 62 ms
68,596 KB
testcase_37 AC 51 ms
64,576 KB
testcase_38 AC 48 ms
61,972 KB
testcase_39 AC 55 ms
66,120 KB
testcase_40 AC 51 ms
64,464 KB
testcase_41 AC 46 ms
61,960 KB
testcase_42 AC 40 ms
59,212 KB
testcase_43 AC 41 ms
59,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
inf = 10 ** 18

def dijkstra2(N):
    ind = 0
    D = [inf] * (N)
    seen = [False] * (N)
    D[0] = 0
    while True:
        minv = inf
        ind = N + 1
        for i in range(N):
            if seen[i]:
                continue
            if D[i] < minv:
                ind = i
                minv = D[i]
        if ind == N + 1:
            break
        if ind // (C + 1) == N - 1:
            return D
        seen[ind] = True
        for u, d in G[ind]:
            if seen[u]:
                continue
            D[u] = min(D[u], D[ind] + d)
    return D

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()))
N2 = N * (C + 1)
G = [[] for i in range(N2)]
for i in range(V):
    s, t = S[i] - 1, T[i] - 1
    for c in range(C + 1):
        if c + Y[i] <= C:
            G[s * (C + 1) + c].append((t * (C + 1) + c + Y[i], M[i]))

D = dijkstra2(N2)
ans = inf
for i in range(C + 1):
    ans = min(ans, D[(N - 1) * (C + 1) + i])

print(ans) if ans != inf else print(-1)
0