結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
![]() |
提出日時 | 2025-06-20 00:44:04 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 323 ms / 5,000 ms |
コード長 | 1,307 bytes |
コンパイル時間 | 4,119 ms |
コンパイル使用メモリ | 291,652 KB |
実行使用メモリ | 49,500 KB |
最終ジャッジ日時 | 2025-06-20 00:44:29 |
合計ジャッジ時間 | 17,012 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; vector<int> c(m); rep(i, m) cin >> c[i]; vector Graph((k + 1) * n, vector<pair<int, ll>>()); rep(j, m) { int u, v; cin >> u >> v; --u, --v; rep(i, k + 1) { Graph[i * n + u].push_back({ i * n + v, c[j] }); Graph[i * n + v].push_back({ i * n + u, c[j] }); if (i < k) { Graph[i * n + u].push_back({ (i + 1) * n + v, 0 }); Graph[i * n + v].push_back({ (i + 1) * n + u, 0 }); } } } vector<ll> dist((k + 1) * n, 1e18); dist[0] = 0; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.push({ 0, 0 }); while (!pq.empty()) { auto [d, u] = pq.top(); pq.pop(); if (d > dist[u]) continue; for (auto [v, w] : Graph[u]) { if (dist[v] > d + w) { dist[v] = d + w; pq.push({ dist[v], v }); } } } ll ans = 1e18; rep(i, k + 1) ans = min(ans, dist[i * n + n - 1]); if (ans == 1e18) ans = -1; cout << ans << '\n'; return 0; }