結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2019-03-22 23:41:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 501 ms / 4,000 ms |
コード長 | 1,133 bytes |
コンパイル時間 | 1,961 ms |
コンパイル使用メモリ | 182,780 KB |
実行使用メモリ | 24,744 KB |
最終ジャッジ日時 | 2024-11-23 19:12:40 |
合計ジャッジ時間 | 8,194 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, m; cin >> n >> m; vector<vector<pair<int64_t, int>>> g(n); for (int i = 0; i < m; i++) { int64_t a, b, c; cin >> a >> b >> c; a--; b--; g[a].push_back({c, b}); g[b].push_back({c, a}); } vector<vector<int64_t>> dist(n, vector<int64_t>(2, (1LL << 60))); dist[0][0] = 0; priority_queue<pair<int64_t, pair<int, int>>, vector<pair<int64_t, pair<int, int>>>, greater<>> pq; pq.push({dist[0][0], {0, 0}}); while (!pq.empty()) { int64_t score = pq.top().first; int x = pq.top().second.first; int y = pq.top().second.second; pq.pop(); if (dist[x][y] < score) { continue; } for (auto &p : g[x]) { int64_t cost = p.first; int to = p.second; if (dist[x][y] + cost < dist[to][y]) { dist[to][y] = dist[x][y] + cost; pq.push({dist[to][y], {to, y}}); } if (y == 0) { if (dist[x][y] < dist[to][1]) { dist[to][1] = dist[x][y]; pq.push({dist[to][1], {to, 1}}); } } } } cout << 0 << endl; for (int i = 1; i < n; i++) { cout << dist[i][0] + dist[i][1] << endl; } return 0; }