結果
| 問題 | No.3111 Toll Optimization |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-19 20:39:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 105 ms / 5,000 ms |
| コード長 | 1,173 bytes |
| 記録 | |
| コンパイル時間 | 2,306 ms |
| コンパイル使用メモリ | 207,316 KB |
| 実行使用メモリ | 12,872 KB |
| 最終ジャッジ日時 | 2025-04-19 20:39:41 |
| 合計ジャッジ時間 | 7,831 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 70 |
ソースコード
#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 ofs = v / n * n, fr = v - ofs;
if(fr == n - 1){
cout << d << '\n';
return 0;
}
for(auto [u, w] : g[fr]){
u += ofs;
if(d + w < dp[u]){
dp[u] = d + w;
pq.emplace(dp[u], u);
}
if(u + n < dp.size() && d < dp[u + n]){
dp[u + n] = d;
pq.emplace(d, u + n);
}
}
}
cout << "-1\n";
}