結果
| 問題 | 
                            No.3111 Toll Optimization
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-09-21 19:20:28 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 167 ms / 5,000 ms | 
| コード長 | 2,260 bytes | 
| コンパイル時間 | 3,271 ms | 
| コンパイル使用メモリ | 295,372 KB | 
| 実行使用メモリ | 14,812 KB | 
| 最終ジャッジ日時 | 2025-09-21 19:20:39 | 
| 合計ジャッジ時間 | 9,654 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 70 | 
ソースコード
#include <bits/stdc++.h>
[[nodiscard]] static inline constexpr std::vector<std::vector<std::pair<uint_least32_t, uint_least32_t>>> prepare(const uint_fast32_t N, const uint_fast32_t M, const std::vector<uint_least32_t>& C, const std::vector<std::pair<uint_least32_t, uint_least32_t>>& bridges) noexcept
{
	std::vector<std::vector<std::pair<uint_least32_t, uint_least32_t>>> next_of(N + 1);
	for (uint_fast32_t i = 0; i != M; ++i)
		next_of[bridges[i].first].emplace_back(bridges[i].second, C[i]), next_of[bridges[i].second].emplace_back(bridges[i].first, C[i]);
	return next_of;
}
[[nodiscard]] static inline int_fast64_t solve(const uint_fast32_t N, const uint_fast32_t K, const std::vector<std::vector<std::pair<uint_least32_t, uint_least32_t>>>& next_of) noexcept
{
	std::vector<std::array<uint_least64_t, 4>> dist(N + 1, { UINT_LEAST64_MAX, UINT_LEAST64_MAX, UINT_LEAST64_MAX, UINT_LEAST64_MAX });
	std::priority_queue<std::tuple<uint_least64_t, uint_least32_t, uint_least32_t>, std::vector<std::tuple<uint_least64_t, uint_least32_t, uint_least32_t>>, std::greater<std::tuple<uint_least64_t, uint_least32_t, uint_least32_t>>> pq;
	for (uint_fast32_t i = 0; i <= K; ++i) dist[1][i] = 0, pq.emplace(0, i, 1);
	while (!pq.empty())
	{
		const auto [cur_dist, used_ticket, cur_pos] = pq.top();
		const auto& next = next_of[cur_pos];
		pq.pop();
		if (cur_dist != dist[cur_pos][used_ticket]) continue;
		for (uint_fast32_t i = 0; i != next.size(); ++i)
		{
			if (dist[next[i].first][used_ticket] > cur_dist + next[i].second)
				dist[next[i].first][used_ticket] = cur_dist + next[i].second, pq.emplace(cur_dist + next[i].second, used_ticket, next[i].first);
			if (used_ticket < K && dist[next[i].first][used_ticket + 1] > cur_dist)
				dist[next[i].first][used_ticket + 1] = cur_dist, pq.emplace(cur_dist, used_ticket + 1, next[i].first);
		}
	}
	return dist[N][K];
}
int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	uint_fast32_t N, M, K;
	std::cin >> N >> M >> K;
	std::vector<uint_least32_t> C(M);
	std::vector<std::pair<uint_least32_t, uint_least32_t>> bridges(M);
	for (auto& c : C) std::cin >> c;
	for (auto& [u, v] : bridges) std::cin >> u >> v;
	std::cout << solve(N, K, prepare(N, M, C, bridges)) << '\n';
	return 0;
}