結果
問題 | No.807 umg tours |
ユーザー | ldsyb |
提出日時 | 2019-03-22 23:41:15 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 565 ms / 4,000 ms |
コード長 | 1,133 bytes |
コンパイル時間 | 1,927 ms |
コンパイル使用メモリ | 179,444 KB |
実行使用メモリ | 24,880 KB |
最終ジャッジ日時 | 2023-08-15 12:09:11 |
合計ジャッジ時間 | 9,014 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,384 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,384 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 3 ms
4,384 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,384 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,384 KB |
testcase_11 | AC | 283 ms
15,256 KB |
testcase_12 | AC | 318 ms
15,428 KB |
testcase_13 | AC | 416 ms
18,656 KB |
testcase_14 | AC | 171 ms
10,288 KB |
testcase_15 | AC | 132 ms
8,884 KB |
testcase_16 | AC | 429 ms
19,240 KB |
testcase_17 | AC | 565 ms
24,508 KB |
testcase_18 | AC | 553 ms
24,436 KB |
testcase_19 | AC | 537 ms
22,392 KB |
testcase_20 | AC | 323 ms
15,736 KB |
testcase_21 | AC | 338 ms
16,292 KB |
testcase_22 | AC | 134 ms
8,968 KB |
testcase_23 | AC | 103 ms
7,464 KB |
testcase_24 | AC | 298 ms
22,472 KB |
testcase_25 | AC | 561 ms
24,880 KB |
ソースコード
#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; }