#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #include <list> #include <atcoder/all> #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair<int, int> P; int main() { int n, m; cin>>n>>m; int t[101]; vector<P> g[101]; for(int i=0; i<m; i++){ int a, b, c; cin>>a>>b>>c; a--; b--; g[a].push_back({b, c}); g[b].push_back({a, c}); } for(int i=0; i<n; i++) cin>>t[i]; int dp[101][1010]; const int INF=1e9+7; for(int i=0; i<n; i++){ fill(dp[i], dp[i]+1001, INF); } dp[0][0]=0; using Pi=pair<int, P>; priority_queue<Pi, vector<Pi>, greater<Pi>> que; que.push({0, {0, 0}}); while(!que.empty()){ auto p=que.top(); que.pop(); int x=p.second.first, s=p.second.second; if(dp[x][s]<p.first) continue; int s1=min(1000, s+t[x]); for(auto q:g[x]){ int y=q.first; int c=q.second; if(dp[y][s1]>dp[x][s]+c/s1+t[x]){ dp[y][s1]=dp[x][s]+c/s1+t[x]; que.push({dp[y][s1], {y, s1}}); } } } int ans=INF; for(int i=0; i<=1000; i++) ans=min(ans, dp[n-1][i]); cout<<ans<<endl; return 0; }