結果
問題 | No.807 umg tours |
ユーザー | merom686 |
提出日時 | 2019-03-22 21:52:52 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 269 ms / 4,000 ms |
コード長 | 1,725 bytes |
コンパイル時間 | 914 ms |
コンパイル使用メモリ | 83,932 KB |
実行使用メモリ | 25,188 KB |
最終ジャッジ日時 | 2023-08-15 11:55:23 |
合計ジャッジ時間 | 5,137 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,384 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 166 ms
18,112 KB |
testcase_12 | AC | 132 ms
15,000 KB |
testcase_13 | AC | 196 ms
19,276 KB |
testcase_14 | AC | 68 ms
10,112 KB |
testcase_15 | AC | 49 ms
8,736 KB |
testcase_16 | AC | 202 ms
20,248 KB |
testcase_17 | AC | 269 ms
25,136 KB |
testcase_18 | AC | 262 ms
25,188 KB |
testcase_19 | AC | 249 ms
22,260 KB |
testcase_20 | AC | 106 ms
13,144 KB |
testcase_21 | AC | 107 ms
13,560 KB |
testcase_22 | AC | 38 ms
7,936 KB |
testcase_23 | AC | 29 ms
6,748 KB |
testcase_24 | AC | 83 ms
18,836 KB |
testcase_25 | AC | 263 ms
24,872 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <queue> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; struct Graph { struct VertexQ { bool operator<(const VertexQ& o) const { return c > o.c; // 逆 } int i; ll c; }; struct Vertex { int n; ll c; }; struct Edge { int i, n, c; }; Graph(int n, int m) : v(n, { -1 }), e(m), n(n), m(0) {} void add_edge(int i, int j, int c) { e[m] = { j, v[i].n, c }; v[i].n = m; m++; } void dijkstra(int i) { for (int i = 0; i < n; i++) v[i].c = 1LL << 60; priority_queue<VertexQ> q; q.push({ i, v[i].c = 0 }); while (!q.empty()) { auto p = q.top(); q.pop(); if (p.c > v[p.i].c) continue; for (int j = v[p.i].n; j >= 0; j = e[j].n) { Edge& o = e[j]; ll c = p.c + o.c; if (c < v[o.i].c) q.push({ o.i, v[o.i].c = c }); } } } vector<Vertex> v; vector<Edge> e; int n, m; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; Graph g(n * 2, m * 3 * 2); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; g.add_edge(a, b, c); g.add_edge(b, a, c); g.add_edge(a, b + n, 0); g.add_edge(b, a + n, 0); g.add_edge(a + n, b + n, c); g.add_edge(b + n, a + n, c); } g.dijkstra(0); cout << 0 << '\n'; for (int i = 1; i < n; i++) { cout << g.v[i].c + g.v[i + n].c << '\n'; } return 0; }