結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-25 15:26:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 441 ms / 4,000 ms |
| コード長 | 1,394 bytes |
| コンパイル時間 | 1,850 ms |
| コンパイル使用メモリ | 178,372 KB |
| 実行使用メモリ | 19,808 KB |
| 最終ジャッジ日時 | 2024-11-23 19:22:44 |
| 合計ジャッジ時間 | 7,905 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to; long long dist;
edge(int t, long long d) {
to = t; dist = d;
}
};
int main() {
int n, m; cin >> n >> m;
vector<edge> v[n];
for (int i = 0; i < m; i++) {
int a, b; long long c;
cin >> a >> b >> c;
v[a-1].emplace_back(b-1, c);
v[b-1].emplace_back(a-1, c);
}
vector<long long> d(n, 1e17), d2(n, 1e17);
d[0] = 0; d2[0] = 0;
priority_queue<pair<long long, int>> pq;
pq.push({d[0], 0});
while (!pq.empty()) {
int cur = pq.top().second;
long long dist = -pq.top().first;
pq.pop();
if (dist != d[cur]) continue;
for (auto e: v[cur]) {
if (d[e.to] > d[cur] + e.dist) {
d[e.to] = d[cur] + e.dist;
pq.push({-d[e.to], e.to});
}
}
}
pq.push({d2[0], 0});
while (!pq.empty()) {
int cur = pq.top().second;
long long dist = -pq.top().first;
pq.pop();
if (dist != d2[cur]) continue;
for (auto e: v[cur]) {
if (d2[e.to] > min(d2[cur] + e.dist, d[cur])) {
d2[e.to] = min(d2[cur] + e.dist, d[cur]);
pq.push({-d2[e.to], e.to});
}
}
}
for (int i = 0; i < n; i++) {
cout << d[i] + d2[i] << endl;
}
return 0;
}