結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
|
提出日時 | 2025-04-19 20:33:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,206 bytes |
コンパイル時間 | 2,294 ms |
コンパイル使用メモリ | 208,692 KB |
実行使用メモリ | 15,516 KB |
最終ジャッジ日時 | 2025-04-19 20:33:45 |
合計ジャッジ時間 | 9,309 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 47 WA * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> c(m); for(auto &&v : c) cin >> v; vector<vector<pair<int,int>>> g(n); for(int i = 0; i < m; i++){ int u, v; cin >> u >> v; u--, v--; g[u].emplace_back(v, c[i]); g[v].emplace_back(u, c[i]); } priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq; vector<ll> dp(n * (k + 1), 1ll << 60); dp[0] = 0; pq.emplace(0, 0); while(!pq.empty()){ auto [d, v] = pq.top(); pq.pop(); if(d > dp[v]) continue; int cv = v / n, fr = v - cv * n; for(auto [u, w] : g[fr]){ if(d + w < dp[u]){ dp[u] = d + w; pq.emplace(dp[u], u); } if(cv >= k) continue; if(d < dp[u + n]){ dp[u + n] = d; pq.emplace(d, u + n); } } } ll ans = 1ll << 60; int v = n - 1; while(v < dp.size()) ans = min(ans, dp[v]), v += n; if(ans >> 60) ans = -1; cout << ans << '\n'; }