結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:48:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 129 ms / 5,000 ms |
コード長 | 1,312 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 82,912 KB |
実行使用メモリ | 78,068 KB |
最終ジャッジ日時 | 2025-03-20 20:48:23 |
合計ジャッジ時間 | 4,179 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
import heapqdef main():n = int(input())c = int(input())v_num = 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()))adj = [[] for _ in range(n + 1)]for i in range(v_num):s = s_list[i]t = t_list[i]y = y_list[i]m = m_list[i]adj[s].append((t, y, m))INF = float('inf')dp = [[INF] * (c + 1) for _ in range(n + 1)]dp[1][0] = 0heap = []heapq.heappush(heap, (0, 1, 0))while heap:current_time, u, current_cost = heapq.heappop(heap)if current_time > dp[u][current_cost]:continuefor edge in adj[u]:v, y, m = edgenew_cost = current_cost + yif new_cost > c:continuenew_time = current_time + mif new_time < dp[v][new_cost]:dp[v][new_cost] = new_timeheapq.heappush(heap, (new_time, v, new_cost))min_time = INFfor cost in range(c + 1):if dp[n][cost] < min_time:min_time = dp[n][cost]print(-1 if min_time == INF else min_time)if __name__ == "__main__":main()