結果
| 問題 |
No.3111 Toll Optimization
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-19 05:36:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,423 ms / 5,000 ms |
| コード長 | 897 bytes |
| コンパイル時間 | 410 ms |
| コンパイル使用メモリ | 82,736 KB |
| 実行使用メモリ | 154,496 KB |
| 最終ジャッジ日時 | 2025-04-19 05:37:53 |
| 合計ジャッジ時間 | 52,789 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 70 |
ソースコード
#!/usr/bin/env python3
import sys
import threading
import heapq
INF = 10**30
N, M, K = map(int, input().split())
costs = list(map(int, input().split()))
adj = [[] for _ in range(N + 1)]
for i in range(M):
u, v = map(int, input().split())
c = costs[i]
adj[u].append((v, c))
adj[v].append((u, c))
dist = [[INF] * (K + 1) for _ in range(N + 1)]
dist[1][0] = 0
pq = [(0, 1, 0)]
while pq:
cost_so_far, u, used = heapq.heappop(pq)
if cost_so_far > dist[u][used]:
continue
for v, w in adj[u]:
nc = cost_so_far + w
if nc < dist[v][used]:
dist[v][used] = nc
heapq.heappush(pq, (nc, v, used))
if used < K:
if cost_so_far < dist[v][used + 1]:
dist[v][used + 1] = cost_so_far
heapq.heappush(pq, (cost_so_far, v, used + 1))
ans = min(dist[N])
print(ans if ans < INF else -1)