#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; struct edge { int to, cost; }; int main() { int N, M; cin >> N >> M; vector> g(N); 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}); } vector t(N); for (int i = 0; i < N; i++) cin >> t[i]; vector> dist(N, vector(1010, 1e18)); dist[0][0] = 0; priority_queue, vector>, greater>> pq; pq.push({0, 0, 0}); while (!pq.empty()) { auto [c, v, p] = pq.top(); pq.pop(); if (dist[v][p] < c) continue; c += t[v]; p = min(p + t[v], 1001LL); for (auto e: g[v]) { if (dist[e.to][p] > c + e.cost / p) { dist[e.to][p] = c + e.cost / p; pq.push({c + e.cost /p, e.to, p}); } } } ll ans = 1e18; for (int i = 0; i <= 1001; i++) ans = min(ans, dist[N - 1][i]); cout << ans << endl; return 0; }