結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
|
提出日時 | 2025-06-30 21:29:34 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,785 bytes |
コンパイル時間 | 6,172 ms |
コンパイル使用メモリ | 335,828 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2025-06-30 21:29:55 |
合計ジャッジ時間 | 17,586 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 RE * 20 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using ull = unsigned long long; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define NP next_permutation const int INF32 = 2e9; const ll INF64 = 2e18; const ll mod = 998244353; // const ll mod = 1e9 + 7; template<typename T> bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;} template<typename T> bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;} void cincout() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } int main() { cincout(); int N, M, K; cin >> N >> M >> K; vector<int> C(M); for (int i = 0; i < M; i++) cin >> C[i]; using P = pair<ll, ll>; vector<vector<P>> graph(N); for (int i = 0; i < M; i++) { int u, v; cin >> u >> v; u--, v--; graph[u].emplace_back(v, C[i]); graph[v].emplace_back(u, C[i]); } using A = array<ll, 3>; priority_queue<A, vector<A>, greater<A>> pq; pq.push({0, 0, 0}); vector<vector<ll>> dist(N, vector<ll>(3, INF64)); dist[0][0] = 0; while (!pq.empty()) { auto [d, v, k] = pq.top(); pq.pop(); if (dist[v][k] < d) continue; for (auto [next_v, w] : graph[v]) { if (chmin(dist[next_v][k], d + w)) pq.push({dist[next_v][k], next_v, k}); if (k < K && chmin(dist[next_v][k + 1], d)) pq.push({dist[next_v][k + 1], next_v, k + 1}); } } ll ans = *min_element(all(dist[N - 1])); cout << (ans != INF64 ? ans : -1) << endl; }