結果
| 問題 |
No.3111 Toll Optimization
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-19 00:10:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,541 bytes |
| コンパイル時間 | 1,604 ms |
| コンパイル使用メモリ | 178,744 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-19 00:10:49 |
| 合計ジャッジ時間 | 11,917 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 70 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
33 | auto [cost, u, k] = pq.top();
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
struct Edge {
int to;
ll cost;
};
int main() {
int N, M, K;
cin >> N >> M >> K;
vector<vector<Edge>> graph(N + 1); // 1-indexed
for (int i = 0; i < M; ++i) {
int u, v;
ll c;
cin >> u >> v >> c;
graph[u].push_back({v, c});
graph[v].push_back({u, c});
}
// dist[node][used_coupon]
vector<vector<ll>> dist(N + 1, vector<ll>(K + 1, INF));
priority_queue<tuple<ll, int, int>, vector<tuple<ll, int, int>>, greater<>> pq;
dist[1][0] = 0;
pq.emplace(0, 1, 0); // cost, node, used_coupon
while (!pq.empty()) {
auto [cost, u, k] = pq.top();
pq.pop();
if (cost > dist[u][k]) continue;
for (auto& e : graph[u]) {
// クーポンを使わずに移動
if (dist[e.to][k] > dist[u][k] + e.cost) {
dist[e.to][k] = dist[u][k] + e.cost;
pq.emplace(dist[e.to][k], e.to, k);
}
// クーポンを使って無料で移動(まだ使えるなら)
if (k < K && dist[e.to][k + 1] > dist[u][k]) {
dist[e.to][k + 1] = dist[u][k];
pq.emplace(dist[e.to][k + 1], e.to, k + 1);
}
}
}
// 最終的に町Nに到達する最小コストを、クーポンの使用数を変えて全部見る
ll ans = *min_element(dist[N].begin(), dist[N].end());
cout << ans << '\n';
return 0;
}