#include #include using namespace std; using namespace atcoder; using ll=long long; using ull=unsigned long long; using ld=long double; using i128=__int128; using P=pair; template using vc=vector; template using vv=vc>; using vl=vc; using vvl=vc>; using vul=vc; using vs=vc; using vb=vc; #define rep(i,s,n) for(ll i=s;i<(n);i++) #define Rep(i,s,n) for(ll i=n;i>=s;i--) #define nall(x) x.begin(),x.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define eb emplace_back #define pob pop_back #define nexp(v) next_permutation(v) #define prep(v) prev_permutation(v) #define YES cout<<"Yes"<b)a=b;} void chmax(ll &a,ll b){if(a> n >> m; vv

g(n); rep(i,0,m){ ll u,v,w; cin >> u >> v >> w; u--,v--; g[u].pb({v,w}); g[v].pb({u,w}); } vl a(n),b(n),c(n); rep(i,0,n)cin >> a[i]; rep(i,0,n)cin >> b[i]; rep(i,0,n)cin >> c[i]; vl dist(n,INF); priority_queue,greater

> pq; dist[0]=0; pq.push({0,0}); auto time=[&](auto v,auto t)->ll{ ll cnt=max(1LL,ceil_div(t,a[v])),x=cnt*a[v]; if(cnt%b[v]!=0)return x; if(b[v]==1)return x+c[v]; else return x+min(a[v],c[v]); }; while(!pq.empty()){ auto [d,now]=pq.top(); pq.pop(); if(d!=dist[now])continue; ll ti=time(now,d); for(auto [nxt,nw]:g[now]){ ll nc=nw+ti; if(nc