#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- template using min_priority_queue = priority_queue, greater>; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M, K; ll C[101010]; vector> E[101010]; int vis[101010][4]; ll D[101010][4]; void _main() { cin >> N >> M >> K; rep(i, 0, M) cin >> C[i]; rep(i, 0, M) { int a, b; cin >> a >> b; a--; b--; E[a].push_back({ b, C[i] }); E[b].push_back({ a, C[i] }); } rep(town, 0, N) rep(coupon, 0, K + 1) D[town][coupon] = infl; rep(town, 0, N) rep(coupon, 0, K + 1) vis[town][coupon] = 0; min_priority_queue>> que; D[0][K] = 0; que.push({ 0, {0, K} }); while (!que.empty()) { auto q = que.top(); que.pop(); ll cst = q.first; int town = q.second.first; int coupon = q.second.second; if (vis[town][coupon]) continue; vis[town][coupon] = 1; fore(p, E[town]) { ll cst2 = cst + p.second; int town2 = p.first; // use coupon if (coupon > 0) { if (chmin(D[town2][coupon - 1], cst)) que.push({ D[town2][coupon - 1], { town2, coupon - 1 } }); } // not use coupon if (chmin(D[town2][coupon], cst2)) que.push({ D[town2][coupon], { town2, coupon } }); } } ll ans = infl; rep(coupon, 0, K + 1) chmin(ans, D[N - 1][coupon]); if (ans == infl) ans = -1; cout << ans << endl; }