結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
![]() |
提出日時 | 2025-04-19 08:44:47 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 294 ms / 5,000 ms |
コード長 | 1,500 bytes |
コンパイル時間 | 3,967 ms |
コンパイル使用メモリ | 295,616 KB |
実行使用メモリ | 20,444 KB |
最終ジャッジ日時 | 2025-04-19 08:45:01 |
合計ジャッジ時間 | 12,451 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; const int iinf = 1e9; const ll inf = 1e18; template<typename T> ostream& operator<<(ostream &o, vector<T> v) { for (int i = 0; i < v.size(); i++) o << v[i] << (i+1<v.size()?" ":""); return o; } struct Edge { int to; ll cost; }; int main() { cin.tie(0)->sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector<vector<Edge>> G(N+1); vector<ll> C(M); vector<int> U(M), V(M); for(int i = 0; i < M; i++){ cin >> C[i]; } for(int i = 0; i < M; i++){ cin >> U[i] >> V[i]; G[U[i]].push_back({V[i], C[i]}); G[V[i]].push_back({U[i], C[i]}); } vector<vector<ll>> dist(N+1, vector<ll>(K+1, inf)); using T = tuple<ll,int,int>; priority_queue<T, vector<T>, greater<T>> pq; dist[1][0] = 0; pq.emplace(0, 1, 0); while(!pq.empty()){ auto [d, v, k] = pq.top(); pq.pop(); if(d > dist[v][k]) continue; for(auto &e : G[v]){ int u = e.to; ll c = e.cost; if(dist[u][k] > d + c){ dist[u][k] = d + c; pq.emplace(dist[u][k], u, k); } if(k < K && dist[u][k+1] > d){ dist[u][k+1] = d; pq.emplace(d, u, k+1); } } } ll ans = inf; for(int k = 0; k <= K; k++){ ans = min(ans, dist[N][k]); } cout << (ans==inf?-1:ans) << "\n"; return 0; }