#include #include #include using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 int main(){ int N,M; cin>>N>>M; vector>> E(N); rep(i,M){ int a,b,c; cin>>a>>b>>c; a--;b--; E[a].emplace_back(b,c); E[b].emplace_back(a,c); } vector T(N); rep(i,N)cin>>T[i]; vector> dis(N,vector(1002,Inf)); priority_queue>,vector>>,greater>>> Q; Q.emplace(T[0],make_pair(0,T[0])); dis[0][T[0]] = T[0]; while(Q.size()>0){ int D = Q.top().first; int u = Q.top().second.first; int t = Q.top().second.second; Q.pop(); if(dis[u][t]!=D)continue; rep(i,E[u].size()){ int v = E[u][i].first; int c = E[u][i].second; int D2 = T[v] + c/t; int nt = min(1001,t + T[v]); if(dis[v][nt]>D+D2){ dis[v][nt] = D+D2; Q.emplace(D+D2,make_pair(v,nt)); } } } int ans = Inf; rep(i,1002)ans = min(ans,dis.back()[i]); cout<