#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using ull = unsigned long long; using Graph = vector>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define NP next_permutation const int INF32 = 2e9; const ll INF64 = 2e18; const ll mod = 998244353; // const ll mod = 1e9 + 7; template bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;} void cincout() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } int main() { cincout(); int N, M, K; cin >> N >> M >> K; vector C(M); for (int i = 0; i < M; i++) cin >> C[i]; using P = pair; vector> graph(N); for (int i = 0; i < M; i++) { int u, v; cin >> u >> v; u--, v--; graph[u].emplace_back(v, C[i]); graph[v].emplace_back(u, C[i]); } priority_queue, greater

> pq; pq.push({0, 0}); vector dist(N, INF64); dist[0] = 0; while (!pq.empty()) { auto [d, v] = pq.top(); pq.pop(); if (dist[v] < d) continue; for (auto [next_v, w] : graph[v]) { if (chmin(dist[next_v], d + w)) pq.emplace(dist[next_v], next_v); } } if (dist[N - 1] == INF64) { cout << -1 << endl; return 0; } vector max_w; int v = N - 1; while (v != 0) { for (auto [prev_v, w] : graph[v]) { if (dist[prev_v] + w == dist[v]) { max_w.push_back(w); v = prev_v; break; } } } sort(rall(max_w)); ll sum = 0; for (int i = 0; i < min(K, (int)max_w.size()); i++) sum += max_w[i]; cout << dist[N - 1] - sum << endl; }