結果
| 問題 | No.3111 Toll Optimization |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-21 20:32:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,834 ms / 5,000 ms |
| コード長 | 1,492 bytes |
| 記録 | |
| コンパイル時間 | 495 ms |
| コンパイル使用メモリ | 82,520 KB |
| 実行使用メモリ | 129,796 KB |
| 最終ジャッジ日時 | 2025-06-21 20:33:19 |
| 合計ジャッジ時間 | 47,430 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 70 |
ソースコード
## https://yukicoder.me/problems/no/3111
import heapq
MAX_INT = 10 ** 18
def main():
N, M, K = map(int, input().split())
C = list(map(int, input().split()))
next_nodes = [[] for _ in range(N)]
for i in range(M):
u, v = map(int, input().split())
next_nodes[u -1 ].append((v - 1, C[i]))
next_nodes[v - 1].append((u - 1, C[i]))
queue = []
seen = [[MAX_INT] * N for _ in range(K + 1)]
fix = [[MAX_INT] * N for _ in range(K + 1)]
seen[0][0] = 0
heapq.heappush(queue, (0, 0, 0))
while len(queue) > 0:
cost, count, v = heapq.heappop(queue)
if fix[count][v] < MAX_INT:
continue
fix[count][v] = cost
for w, c in next_nodes[v]:
if count + 1 <= K:
if fix[count + 1][w] == MAX_INT:
new_cost = cost
if seen[count + 1][w] > new_cost:
seen[count + 1][w] = new_cost
heapq.heappush(queue, (new_cost, count + 1, w))
if fix[count][w] < MAX_INT:
continue
new_cost = cost + c
if seen[count][w] > new_cost:
seen[count][w] = new_cost
heapq.heappush(queue, (new_cost, count, w))
x = MAX_INT
for c in range(K + 1):
x = min(x, fix[c][N - 1])
if x == MAX_INT:
print(-1)
else:
print(x)
if __name__ == "__main__":
main()