#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; int main() { int N, M; cin >> N >> M; vector> g(N); map, int> edge; for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--, b--; g[a].push_back(b); g[b].push_back(a); edge[make_pair(a, b)] = c; } vector t(N); for (int i = 0; i < N; i++) cin >> t[i]; vector dist(N, 1e18); dist[0] = t[0]; vector cost(N, 0); cost[0] = t[0]; priority_queue, vector>, greater>> pq; pq.push(make_pair(t[0], 0)); //vector vis(N, false); //vis[0] = true; while (!pq.empty()) { auto [d, u] = pq.top(); pq.pop(); for (auto v: g[u]) { //if (vis[v]) continue; if (dist[v] > dist[u] + t[v] + edge[make_pair(min(u, v), max(u, v))] / cost[u]) { cost[v] = cost[u] + t[v]; dist[v] = dist[u] + t[v] + edge[make_pair(min(u, v), max(u, v))] / cost[u]; //vis[v] = true; pq.push(make_pair(dist[v], v)); } } } //for (int i = 0; i < N; i++) cout << cost[i] << " \n"[i == N - 1]; //for (int i = 0; i < N; i++) cout << dist[i] << " \n"[i == N - 1]; cout << dist[N - 1] << endl; return 0; }