結果

問題 No.1 道のショートカット
コンテスト
ユーザー yura1685
提出日時 2026-05-30 14:50:13
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 44 ms / 5,000 ms
+ 758µs
コード長 585 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 82 ms
コンパイル使用メモリ 65,320 KB
実行使用メモリ 60,432 KB
最終ジャッジ日時 2026-10-13 13:27:03
合計ジャッジ時間 4,729 ms
ジャッジサーバーID
(参考情報)
<nil> / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

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