#include #include using namespace std; using namespace atcoder; using ld = long double; using ll = long long; using ull = unsigned long long; using VB = vector; using VVB = vector; using VC = vector; using VVC = vector; using VI = vector; using VVI = vector; using VVVI = vector; using VL = vector; using VVL = vector; using VVVL = vector; using VD = vector; using VVD = vector; using VT = vector; using VVT = vector; using P = pair; using VP = vector

; using VVP = vector; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++) #define ALL(a) (a).begin(),(a).end() constexpr int INF = 1001001001; constexpr ll LINF = 1001001001001001001ll; //constexpr ll LINF = 8e18; //constexpr int DX[] = {-1, -1, 0, 0, 1, 1}; //constexpr int DY[] = {-1, 0, -1, 1, 0, 1}; constexpr int DX[] = {1, 0, -1, 0, 0, 0}; constexpr int DY[] = {0, 1, 0, -1, 0, 0}; //constexpr int DZ[] = {0, 0, 0, 0, 1, -1}; template< typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true); } template< typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true); } using mint = modint998244353; //using mint = modint1000000007; using VM = vector; using VVM = vector; using VVVM = vector; using VVVVM = vector; inline ll divceil(ll x, ll y) { if(x >= 0) return (x + y - 1) / y; else return -((-x) / y); } inline ll divfloor(ll x, ll y) { if(x >= 0) return x / y; else return -((- x + y - 1) / y); } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; cin >> n >> m; VVP e(n); REP(i, m) { int u, v, w; cin >> u >> v >> w; u--; v--; e[u].push_back({v, w}); e[v].push_back({u, w}); } VL a(n), b(n), c(n), d(n, 8e18); REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; REP(i, n) cin >> c[i]; d[0] = 0; priority_queue

q; q.push({0, 0}); while (!q.empty()) { int u = q.top().second; ll t = -q.top().first; q.pop(); if (d[u] != t) continue; for (P p : e[u]) { int v = p.first; ll w = p.second; ll z = (max(t, 1ll) + a[u] - 1) / a[u] * a[u]; if (z / a[u] % b[u]) { w += z; } else { w += z + min(c[u], a[u]); } if (d[v] <= w) continue; d[v] = w; q.push({-w, v}); } } cout << d[n - 1] << endl; //REP(i, n) cout << d[i] << endl; }