結果
| 問題 | No.3111 Toll Optimization |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-11 19:03:18 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,096 bytes |
| 記録 | |
| コンパイル時間 | 6,837 ms |
| コンパイル使用メモリ | 267,016 KB |
| 実行使用メモリ | 12,928 KB |
| 最終ジャッジ日時 | 2025-09-11 19:03:39 |
| 合計ジャッジ時間 | 21,060 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 19 WA * 1 RE * 50 |
ソースコード
#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[v][t] != 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";
}