結果
問題 | No.1449 新プロランド |
ユーザー | Example0911 |
提出日時 | 2021-03-31 14:59:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,386 bytes |
コンパイル時間 | 3,088 ms |
コンパイル使用メモリ | 205,804 KB |
最終ジャッジ日時 | 2025-01-20 01:41:37 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include "bits/stdc++.h" #define int long long using namespace std; using ll = long long; using P = pair<ll, pair<ll, ll>>; const ll INF = (1LL << 61); ll mod = 1000000007; int N, M; vector<pair<ll, ll>>edge[110]; int T[110]; vector<vector<ll>> dijkstra(int s) { priority_queue<P, vector<P>, greater<P>>pq; // しおむすびを合計t分食べているという情報を追加 vector<vector<ll>>dist(N, vector<ll>(1010, INF)); dist[s][T[s]] = T[s]; pq.push({ dist[s][T[s]],{s, T[s] } }); while (!pq.empty()) { P p = pq.top(); pq.pop(); ll d = p.first, from = p.second.first, t = p.second.second; if (dist[from][t] < d)continue; for (auto nv : edge[from]) { ll to = nv.first; ll cost = nv.second; cost /= t; if (to != N)cost += T[to]; if (dist[from][t] + cost < dist[to][min(1001LL, t + T[to])]) { dist[to][min(1001LL, t + T[to])] = dist[from][t] + cost; pq.push({ dist[to][min(1001LL, t + T[to])],{to, min(1001LL, t + T[to])} }); } } } return dist; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; for (int i = 0; i < M; i++) { int A, B, C; cin >> A >> B >> C; A--; B--; edge[A].push_back({ B,C }); edge[B].push_back({ A,C }); } for (int i = 0; i < N; i++)cin >> T[i]; auto ans = dijkstra(0); int res = INF; for (int i = 0; i < 1010; i++)res = min(res, ans[N - 1][i]); cout << res << endl; return 0; }