#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; if (n <= 1 || n > 100000) return 1; if (m <= 1 || m > 200000) return 1; vector> path(n); for (int i = 0; i < m; ++i) { ll u, v, w; cin >> u >> v >> w; if (u == v) return 1; if (1 > min(u, v) || n < max(u, v)) return 1; if (w < 1 || 1000000000 < w) return 1; --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]; if (a[i] < 1 || a[i] > 1000000000) return 1; } for (int i = 0; i < n; ++i) { cin >> b[i]; if (b[i] <= 1 || a[i] > 100) return 1; } for (int i = 0; i < n; ++i) { cin >> c[i]; if (c[i] < 1 || c[i] > 1000000000) return 1; } 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; }