#include #include #include #include using namespace std; using ll = long long; using ld = long double; const int INF = (1 << 30) - 10; const ll LINF = 1LL << 60; inline void output_YesNo(bool x) { cout << (x ? "Yes" : "No") << endl; } template inline void chmax(T &lhs, const T &rhs) { lhs = max(lhs, rhs); } template inline void chmin(T &lhs, const T &rhs) { lhs = min(lhs, rhs); } // #include // // void init_output() { cout << fixed << setprecision(15); } struct edge { int to; ll cost; }; struct status { ll cost; int v; bool operator<(const status &rhs) const { return cost < rhs.cost; }; bool operator>(const status &rhs) const { return cost > rhs.cost; }; }; vector dijkstra(int s, vector> &graph) { priority_queue, greater<>> que; vector dis(graph.size(), LINF); dis[s] = 0; que.push({0, s}); while (!que.empty()) { status now = que.top(); que.pop(); if (dis[now.v] < now.cost)continue; for (auto next: graph[now.v]) { if (dis[next.to] > now.cost + next.cost) { dis[next.to] = now.cost + next.cost; que.push({dis[next.to], next.to}); } } } return dis; } int main() { int n, m, k; cin >> n >> m >> k; vector cost(m); for (auto &x: cost)cin >> x; vector> graph(n * (k + 1)); for (int i = 0; i < m; i++) { int from, to; cin >> from >> to, from--, to--; for (int j = 0; j <= k; j++) { int u = from + n * j; int v = to + n * j; graph[u].push_back({v, cost[i]}); graph[v].push_back({u, cost[i]}); if (j >= 1) { graph[u].push_back({v - n, 0}); graph[v].push_back({u - n, 0}); } } } vector dis = dijkstra(n * k, graph); cout << (dis[n - 1] >= LINF ? -1 : dis[n - 1]) << endl; return 0; }