結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:05:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 56 ms / 5,000 ms |
コード長 | 1,008 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,756 KB |
実行使用メモリ | 68,976 KB |
最終ジャッジ日時 | 2025-03-20 21:05:22 |
合計ジャッジ時間 | 3,429 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
n = int(input()) c = int(input()) v = int(input()) s_list = list(map(int, input().split())) t_list = list(map(int, input().split())) y_list = list(map(int, input().split())) m_list = list(map(int, input().split())) edges = [[] for _ in range(n + 1)] for s, t, y, m in zip(s_list, t_list, y_list, m_list): edges[s].append((t, y, m)) INF = float('inf') dp = [[INF] * (c + 1) for _ in range(n + 1)] dp[1][0] = 0 # Starting at town 1 with 0 cost and 0 time for current_town in range(1, n + 1): for current_cost in range(c + 1): if dp[current_town][current_cost] == INF: continue for (next_town, road_cost, time) in edges[current_town]: new_cost = current_cost + road_cost if new_cost > c: continue if dp[next_town][new_cost] > dp[current_town][current_cost] + time: dp[next_town][new_cost] = dp[current_town][current_cost] + time min_time = min(dp[n][:c + 1]) print(-1 if min_time == INF else min_time)