#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector>> Graph(N); for(int i=0; i> u >> v; u--; v--; int w; cin >> w; Graph.at(u).push_back({v,w}); Graph.at(v).push_back({u,w}); } vector dist(N,1e18),A(N),B(N),C(N); for(auto &a : A) cin >> a; for(auto &a : B) cin >> a; for(auto &a : C) cin >> a; priority_queue,vector>,greater<>> Q; dist.at(0) = 0,Q.push({0,0}); while(Q.size()){ auto [d,pos] = Q.top(); Q.pop(); if(dist.at(pos) != d) continue; if(d == 0 || d%A.at(pos)) d += A.at(pos)-d%A.at(pos); if(d/A.at(pos)%B.at(pos) == 0) d += min(A.at(pos),C.at(pos)); for(auto [to,w] : Graph.at(pos)) if(dist.at(to) > d+w) dist.at(to) = d+w,Q.push({d+w,to}); } cout << dist.at(N-1) << endl; }