#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } template using pqueue = priority_queue, greater>; int main() { constexpr auto inf = INT_MAX / 2; constexpr auto lim = 1001; int n, m; cin >> n >> m; auto g = vec>(uns, n, 0); for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; --a; --b; g[a].push_back({ b, c }); g[b].push_back({ a, c }); } auto t = vec(uns, n); for (auto &e : t) cin >> e; pqueue> que; auto dist = vec(inf, n, lim + 1); que.push({ 0, 0, 0 }); dist[0][0] = 0; while (!empty(que)) { auto [d, v, sum] = que.top(); que.pop(); if (dist[v][sum] < d) { continue; } for (auto [u, c] : g[v]) { int p = sum + t[v]; c /= p; chmin(p, lim); if (dist[u][p] <= d + t[v] + c) { continue; } dist[u][p] = d + t[v] + c; que.push({ dist[u][p], u, p }); } } cout << *min_element(begin(dist[n - 1]), end(dist[n - 1])) << endl; }