結果
問題 | No.3111 Toll Optimization |
ユーザー |
|
提出日時 | 2025-04-20 11:11:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 273 ms / 5,000 ms |
コード長 | 1,303 bytes |
コンパイル時間 | 2,076 ms |
コンパイル使用メモリ | 210,964 KB |
実行使用メモリ | 19,708 KB |
最終ジャッジ日時 | 2025-04-20 11:11:40 |
合計ジャッジ時間 | 12,244 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1LL << 60; struct Edge { int to; ll cost; }; int main() { int N, M, K; cin >> N >> M >> K; vector<ll> C(M); for (int i = 0; i < M; ++i) { cin >> C[i]; } vector<vector<Edge>> G(N + 1); for (int i = 0; i < M; ++i) { int u, v; cin >> u >> v; G[u].push_back({v, C[i]}); G[v].push_back({u, C[i]}); } vector<vector<ll>> dist(N + 1, vector<ll>(K + 1, INF)); dist[1][0] = 0; using T = tuple<ll, int, int>; priority_queue<T, vector<T>, greater<>> pq; pq.emplace(0, 1, 0); while (!pq.empty()) { auto [cost, now, used] = pq.top(); pq.pop(); if (dist[now][used] < cost) continue; for (auto& e : G[now]) { if (dist[e.to][used] > cost + e.cost) { dist[e.to][used] = cost + e.cost; pq.emplace(dist[e.to][used], e.to, used); } if (used < K && dist[e.to][used + 1] > cost) { dist[e.to][used + 1] = cost; pq.emplace(cost, e.to, used + 1); } } } ll ans = *min_element(dist[N].begin(), dist[N].end()); if (ans == INF) cout << -1 << endl; else cout << ans << endl; }