結果

問題 No.1 道のショートカット
コンテスト
ユーザー yura1685
提出日時 2026-05-30 14:50:13
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 585 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 307 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 64,768 KB
最終ジャッジ日時 2026-05-30 14:50:28
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, C, M = int(input()), int(input()), int(input())
U = list(map(int, input().split()))
V = list(map(int, input().split()))
Y = list(map(int, input().split()))
T = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(M):
    u, v = U[i]-1, V[i]-1
    G[u].append((v, Y[i], T[i]))

inf = 10 ** 18
dp = [[inf] * (C + 1) for _ in range(N)]
dp[0][0] = 0
for u in range(N-1):
    for v, y, t in G[u]:
        for c in range(C+1):
            if c + y <= C:
                dp[v][c + y] = min(dp[v][c + y], dp[u][c] + t)

ans = min(dp[-1])
print(ans if ans < inf else -1)
0