結果
| 問題 | No.3393 Move on Highway |
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2025-11-28 22:10:35 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 769 ms / 3,000 ms |
| コード長 | 2,657 bytes |
| コンパイル時間 | 3,481 ms |
| コンパイル使用メモリ | 298,512 KB |
| 実行使用メモリ | 29,424 KB |
| 最終ジャッジ日時 | 2025-11-28 22:11:38 |
| 合計ジャッジ時間 | 20,364 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, c; cin >> n >> m >> c;
vector to(n, vector<P>());
rep(i, m) {
int u, v, w; cin >> u >> v >> w;
u--, v--;
to[u].emplace_back(v, w);
to[v].emplace_back(u, w);
}
auto dijkstra = [&](const int st)->vector<long long> {
vector<long long>dp(n, LINF);
dp[st] = 0;
using T = std::pair<long long, int>;
std::priority_queue<T, std::vector<T>, std::greater<T>> pq;
pq.push({ dp[st], st });
while (!pq.empty()) {
auto p = pq.top();
pq.pop();
long long cost = p.first;
int v = p.second;
if (dp[v] < cost) continue;
for (const auto &e : to[v]) {
if (dp[e.first] > dp[v] + e.second + c) {
dp[e.first] = dp[v] + e.second + c;
pq.push({ dp[e.first], e.first });
}
}
}
return dp;
};
auto dp = dijkstra(0);
auto dijkstra2 = [&](const int st)->vector<vector<long long>> {
vector dp(n, vector<long long>(2, LINF));
dp[st][0] = 0;
using T = std::pair<long long, P>;
std::priority_queue<T, std::vector<T>, std::greater<T>> pq;
pq.push({ dp[st][0], {st,0} });
while (!pq.empty()) {
auto p = pq.top();
pq.pop();
long long cost = p.first;
auto[v, t] = p.second;
if (dp[v][t] < cost) continue;
for (const auto &e : to[v]) {
if (t == 0) {
long long ncost = cost + 0 + c;
if (chmin(dp[e.first][1], ncost)) {
pq.push({ ncost,{e.first,1} });
}
}
{
long long ncost = cost + e.second + c;
if (chmin(dp[e.first][t], ncost)) {
pq.push({ ncost,{e.first,t} });
}
}
}
}
return dp;
};
auto dp2 = dijkstra2(n - 1);
rep2(i, 1, n) {
long long ans = dp.back();
long long ans2 = dp[i] + dp2[i][1];
// cout << dp[i] << "_" << dp2[i][1] << endl;
cout << min(ans, ans2) << endl;
}
//cout << dp.back() << endl;
return 0;
}
kwm_t