結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
|
提出日時 | 2025-04-19 00:45:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,167 bytes |
コンパイル時間 | 2,006 ms |
コンパイル使用メモリ | 202,432 KB |
実行使用メモリ | 13,356 KB |
最終ジャッジ日時 | 2025-04-19 00:45:39 |
合計ジャッジ時間 | 7,296 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 66 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int nxm = 1e5 + 10; int n, m, numCoupons; vector<pair<int, int>> g[nxm]; int c[nxm]; long long dist[nxm][4]; void dijkstra(int k) { priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq; pq.push({0, 1}); dist[1][0] = 0; while (!pq.empty()) { auto [d, u] = pq.top(); pq.pop(); if (dist[u][k] < d) continue; for (auto [v, w] : g[u]) { long long keep = d + w; long long use = k > 0 ? dist[u][k - 1] : 1e18; long long newCost = min(keep, use); if (dist[v][k] > newCost) { dist[v][k] = newCost; pq.push({newCost, v}); } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> numCoupons; for (int i = 1; i <= m; i++) cin >> c[i]; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[u].push_back({v, c[i]}); g[v].push_back({u, c[i]}); } memset(dist, 0x3f, sizeof dist); for (int i = 0; i <= numCoupons; i++) { dijkstra(i); } long long ans = 1e18; ans = min(ans, dist[n][numCoupons]); if (ans == 1e18) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }