結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 18:45:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 142 ms / 5,000 ms |
| コード長 | 1,312 bytes |
| コンパイル時間 | 369 ms |
| コンパイル使用メモリ | 82,372 KB |
| 実行使用メモリ | 78,216 KB |
| 最終ジャッジ日時 | 2025-03-20 18:45:27 |
| 合計ジャッジ時間 | 4,680 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
import heapq
def 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] = 0
heap = []
heapq.heappush(heap, (0, 1, 0))
while heap:
current_time, u, current_cost = heapq.heappop(heap)
if current_time > dp[u][current_cost]:
continue
for edge in adj[u]:
v, y, m = edge
new_cost = current_cost + y
if new_cost > c:
continue
new_time = current_time + m
if new_time < dp[v][new_cost]:
dp[v][new_cost] = new_time
heapq.heappush(heap, (new_time, v, new_cost))
min_time = INF
for 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()
lam6er