結果
| 問題 |
No.3111 Toll Optimization
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-19 20:26:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,186 bytes |
| コンパイル時間 | 2,287 ms |
| コンパイル使用メモリ | 207,496 KB |
| 実行使用メモリ | 16,544 KB |
| 最終ジャッジ日時 | 2025-04-19 20:26:46 |
| 合計ジャッジ時間 | 8,014 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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, i);
g[v].emplace_back(u, 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;
if(fr == n - 1){
cout << d << '\n';
return 0;
}
for(auto [u, w] : g[fr]){
w = c[w];
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(dp[u + n], u + n);
}
}
}
cout << "-1\n";
}