#include #include #include using namespace std; #define MAX_V 100002 #define INF 1e15 typedef pair pii; typedef tuple tiii; struct edge{ int to, d; }; int V,E,K; long long weight[MAX_V][3]; vector G[MAX_V]; void dijkstra(int s) { priority_queue, greater> Q; Q.push({0, s, K}); weight[s][K] = 0; while (!Q.empty()) { auto [cost, v, coupons] = Q.top(); Q.pop(); if (weight[v][coupons] < cost) continue; for (int i = 0; i < (int)G[v].size(); i++) { edge &e = G[v][i]; if (coupons > 0 && weight[v][coupons] < weight[e.to][coupons-1]) { weight[e.to][coupons-1] = weight[v][coupons]; Q.push({weight[e.to][coupons-1], e.to, coupons-1}); } if ((long long)weight[v][coupons] + e.d < weight[e.to][coupons]) { weight[e.to][coupons] = weight[v][coupons] + e.d; Q.push({weight[e.to][coupons], e.to, coupons}); } } } } void init() { for (int i = 0; i < MAX_V; i++) { G[i].clear(); for (int j = 0; j < 3; j++) { weight[i][j] = INF; } } cin >> V >> E >> K; vector toll(E); for (int i = 0; i < E; i++) { cin >> toll[i]; } for (int i = 0; i < E; i++) { int u, v; cin >> u >> v; u--; v--; G[u].push_back({v, toll[i]}); G[v].push_back({u, toll[i]}); } } int main() { init(); dijkstra(0); long long ans = INF; for (int i = 0; i < 3; i++) { ans = min(ans, weight[V-1][i]); } cout << (ans == INF ? -1 : ans) << endl; }