#include [[nodiscard]] static inline constexpr std::vector>> prepare(const uint_fast32_t N, const uint_fast32_t M, const std::vector& C, const std::vector>& bridges) noexcept { std::vector>> 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>>& next_of) noexcept { std::vector> dist(N + 1, { UINT_LEAST64_MAX, UINT_LEAST64_MAX, UINT_LEAST64_MAX, UINT_LEAST64_MAX }); std::priority_queue, std::vector>, std::greater>> 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(); pq.pop(); if (cur_dist != dist[cur_pos][used_ticket]) continue; for (const auto& [next_pos, cost] : next_of[cur_pos]) { if (dist[next_pos][used_ticket] > cur_dist + cost) dist[next_pos][used_ticket] = cur_dist + cost, pq.emplace(cur_dist + cost, used_ticket, next_pos); if (used_ticket < K && dist[next_pos][used_ticket + 1] > cur_dist) dist[next_pos][used_ticket + 1] = cur_dist, pq.emplace(cur_dist, used_ticket + 1, next_pos); } } 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 C(M); std::vector> 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; }