#include using namespace std; typedef long long ll; typedef std::pair P; typedef std::priority_queue, std::greater

> PQ; template bool chmax(T& a, U b) { if (a < b) { a = b; return true; } else { return false; } } template bool chmin(T& a, U b) { if (a > b) { a = b; return true; } else { return false; } } int main() { ll n, m; cin >> n >> m; vector> path(n); for (int i = 0; i < m; ++i) { ll u, v, w; cin >> u >> v >> w; --u, --v; path[u].push_back({v, w}); path[v].push_back({u, w}); } vector a(n), b(n), c(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { cin >> b[i]; } for (int i = 0; i < n; ++i) { cin >> c[i]; } vector dist(n, 1e18); dist[0] = 1; PQ pq; pq.push({1, 0}); while (!pq.empty()) { ll u = pq.top().second; ll ud = pq.top().first; pq.pop(); if (ud > dist[u]) continue; for (auto [v, w] : path[u]) { if ((((ud + (a[u] - (ud % a[u])) % a[u])) / a[u]) % b[u]) { if (chmin(dist[v], ud + (a[u] - (ud % a[u])) % a[u] + w)) { pq.push({dist[v], v}); } } else { if (chmin(dist[v], ud + (a[u] - (ud % a[u])) % a[u] + w + min(c[u], a[u]))) { pq.push({dist[v], v}); } } } } cout << dist[n - 1] << endl; }