結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2024-08-02 02:02:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 62 ms / 5,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 329 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 70,676 KB |
最終ジャッジ日時 | 2024-08-02 02:03:03 |
合計ジャッジ時間 | 4,411 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
from collections import defaultdict INF = 1 << 60 N = int(input()) C = int(input()) V = int(input()) S = list(map(lambda x: int(x)-1, input().split())) T = list(map(lambda x: int(x)-1, input().split())) Y = list(map(int, input().split())) M = list(map(int, input().split())) adj = defaultdict(list) for s, t, y, m in zip(S, T, Y, M): adj[s].append((t, y, m)) dp = [[INF] * (C+1) for _ in range(N)] dp[0][0] = 0 # dp[i][j] # i : 町 i にいて # j : コストが j のときの # 最短時間 for i in range(N): for j in range(C): if dp[i][j] == INF: continue for t, y, m in adj[i]: if j+y > C: continue dp[t][j+y] = min(dp[t][j+y], dp[i][j] + m) ans = min(dp[N-1]) if ans == INF: print(-1) else: print(ans)