結果
| 問題 | No.3393 Move on Highway |
| コンテスト | |
| ユーザー |
zjsdut
|
| 提出日時 | 2026-09-01 22:02:58 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 494 ms / 3,000 ms |
| + 572µs | |
| コード長 | 1,614 bytes |
| 記録 | |
| コンパイル時間 | 2,319 ms |
| コンパイル使用メモリ | 349,540 KB |
| 実行使用メモリ | 36,696 KB |
| 最終ジャッジ日時 | 2026-09-01 22:03:24 |
| 合計ジャッジ時間 | 24,751 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
/**
* author: zjs
* created: 01.09.2026 20:29:22
**/
#include <bits/stdc++.h>
#include <cassert> // <bits/stdc++.h> does not include cassert since GCC 16.
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
struct Path {
int to;
long long cost;
int coupon;
};
bool operator<(Path a, Path b) {
return a.cost > b.cost;
}
struct Edge {
int to, w;
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, c;
cin >> n >> m >> c;
vector<vector<Edge>> g(n + 1);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
priority_queue<Path> q;
q.push({1, 0});
vector<long long> dist(n + 1, -1);
while (!q.empty()) {
Path p = q.top();
q.pop();
if (dist[p.to] != -1)
continue;
dist[p.to] = p.cost;
for (Edge e : g[p.to]) {
q.push({e.to, p.cost + e.w + c});
}
}
vector<long long> ans(n + 1, dist[n]);
q.push({n, 0, 1});
vector<vector<bool>> vis(n + 1, vector<bool>(2));
while (!q.empty()) {
Path p = q.top();
q.pop();
if (vis[p.to][p.coupon]) continue;
vis[p.to][p.coupon] = true;
ans[p.to] = min(ans[p.to], dist[p.to] + p.cost);
for (Edge e : g[p.to]) {
q.push({e.to, p.cost + e.w + c, p.coupon});
if (p.coupon)
q.push({e.to, p.cost + c, 0});
}
}
for (int i = 2; i <= n; i++)
cout << ans[i] << '\n';
}
zjsdut