#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp" #include template struct Edge { int src, dst; Cost cost; Edge() = default; Edge(int src, int dst, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge& e) const { return cost < e.cost; } bool operator>(const Edge& e) const { return cost > e.cost; } }; template struct Graph : public std::vector>> { using std::vector>>::vector; void span(bool direct, int src, int dst, Cost cost = 1) { (*this)[src].emplace_back(src, dst, cost); if (!direct) (*this)[dst].emplace_back(dst, src, cost); } }; #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/heap_alias.hpp" #include template using MaxHeap = std::priority_queue; template using MinHeap = std::priority_queue, std::greater>; #line 3 "main.cpp" #include #include #line 6 "main.cpp" using namespace std; constexpr int INF = 1 << 30; constexpr int C = 1000; void solve() { int n, m; cin >> n >> m; Graph graph(n); while (m--) { int u, v, c; cin >> u >> v >> c; graph.span(false, --u, --v, c); } vector ts(n); for (auto& t : ts) cin >> t; auto dp = vector(n, vector(C + 2, INF)); // 食べた時間がCより大なら、移動時間は常に0なので区別不要 MinHeap> heap; // 時間, 頂点, おにぎり時間 dp[0][ts[0]] = ts[0]; heap.emplace(ts[0], 0, ts[0]); while (!heap.empty()) { auto [d, v, t] = heap.top(); heap.pop(); if (dp[v][t] < d) continue; for (auto e : graph[v]) { auto u = e.dst; auto nd = d + e.cost / t + ts[u]; auto nt = min(C + 1, t + ts[u]); if (nd >= dp[u][nt]) continue; dp[u][nt] = nd; heap.emplace(nd, u, nt); } } cout << *min_element(dp[n - 1].begin(), dp[n - 1].end()) << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }