結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
|
提出日時 | 2025-09-11 19:04:06 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 175 ms / 5,000 ms |
コード長 | 1,096 bytes |
コンパイル時間 | 7,584 ms |
コンパイル使用メモリ | 267,340 KB |
実行使用メモリ | 15,372 KB |
最終ジャッジ日時 | 2025-09-11 19:04:23 |
合計ジャッジ時間 | 15,535 ms |
ジャッジサーバーID (参考情報) |
judge / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int maxn = 101010; int n, m, k; int c[maxn]; vector<pair<int,int>> g[maxn]; long dp[4][maxn]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n >> m >> k; for(int i = 0; i < m; i++) cin >> c[i]; for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; g[a].push_back({b,c[i]}); g[b].push_back({a,c[i]}); } memset(dp,0x01,sizeof(dp)); dp[0][0] = 0; priority_queue<pair<long, int>, vector<pair<long,int>>, greater<pair<long,int>>> pq; pq.push({0, 0}); while(!pq.empty()) { auto[e,foo] = pq.top(); pq.pop(); int v = foo / 4, t = foo % 4; if(dp[t][v] != e) continue; for(auto[u, cst]: g[v]) { if(t + 1 <= k) { if(dp[t + 1][u] > dp[t][v]) { dp[t + 1][u] = dp[t][v]; pq.push({dp[t + 1][u], u*4+t+1}); } } if(dp[t][u]>dp[t][v]+cst) { dp[t][u]=dp[t][v]+cst; pq.push({dp[t][u],u*4+t}); } } } long ans = 3467192473289423; for(int i = 0; i <= k; i++) ans = min(ans, dp[i][n-1]); if(ans==3467192473289423) ans = -1; cout << ans << "\n"; }