#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int MAX_N = 101; int g_cost[MAX_N][MAX_N]; vector E[MAX_N]; struct Node { int v; int t; int cost; Node(int v = -1, int t = -1, int cost = -1) { this->v = v; this->t = t; this->cost = cost; } bool operator>(const Node &n) const { return cost > n.cost; } }; int main() { int N, M; cin >> N >> M; int a, b, c; for (int i = 0; i < M; ++i) { cin >> a >> b >> c; E[a].push_back(b); E[b].push_back(a); g_cost[a][b] = c; g_cost[b][a] = c; } vector T(N); for (int i = 0; i < N; ++i) { cin >> T[i]; } priority_queue , greater> pque; pque.push(Node(1, 0, 0)); bool visited[N + 1][2010]; memset(visited, false, sizeof(visited)); int ans = INT_MAX; while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.v][node.t]) continue; visited[node.v][node.t] = true; if (node.v == N) { ans = min(ans, node.cost); continue; } node.t = min(2010, node.t + T[node.v - 1]); node.cost += T[node.v - 1]; for (int u : E[node.v]) { int ncost = node.cost + g_cost[node.v][u] / node.t; pque.push(Node(u, node.t, ncost)); } } cout << ans << endl; return 0; }