結果
| 問題 |
No.3111 Toll Optimization
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-13 01:11:44 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 2,695 ms / 5,000 ms |
| コード長 | 969 bytes |
| コンパイル時間 | 706 ms |
| コンパイル使用メモリ | 12,032 KB |
| 実行使用メモリ | 73,992 KB |
| 最終ジャッジ日時 | 2025-04-15 10:07:38 |
| 合計ジャッジ時間 | 64,110 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 70 |
ソースコード
import heapq
n,m,k = map(int, input().split())
c = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for i in range(m):
u,v = map(int, input().split())
graph[u-1].append((v-1, c[i]))
graph[v-1].append((u-1, c[i]))
start = 0
end = n-1
dist = [[float('inf')] * (k + 1) for _ in range(n)]
dist[start][0] = 0
queue = [(0, start, 0)]
while queue:
now_cost, now_pos, coupon = heapq.heappop(queue)
if dist[now_pos][coupon] < now_cost:
continue
for to, edge_cost in graph[now_pos]:
if coupon < k:
if dist[to][coupon + 1] > now_cost:
dist[to][coupon + 1] = now_cost
heapq.heappush(queue, (now_cost, to, coupon + 1))
if dist[to][coupon] > now_cost + edge_cost:
dist[to][coupon] = now_cost + edge_cost
heapq.heappush(queue, (now_cost + edge_cost, to, coupon))
ans = min(dist[end])
if ans == float('inf'):
print(-1)
else:
print(ans)