結果

問題 No.807 umg tours
ユーザー kyunakyuna
提出日時 2019-10-25 20:30:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 609 ms / 4,000 ms
コード長 1,405 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 89,660 KB
実行使用メモリ 42,216 KB
最終ジャッジ日時 2023-08-15 12:33:01
合計ジャッジ時間 8,272 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 331 ms
32,040 KB
testcase_12 AC 333 ms
24,136 KB
testcase_13 AC 457 ms
32,900 KB
testcase_14 AC 193 ms
15,852 KB
testcase_15 AC 147 ms
13,400 KB
testcase_16 AC 483 ms
34,984 KB
testcase_17 AC 608 ms
42,116 KB
testcase_18 AC 594 ms
41,284 KB
testcase_19 AC 609 ms
39,072 KB
testcase_20 AC 350 ms
22,440 KB
testcase_21 AC 372 ms
23,320 KB
testcase_22 AC 151 ms
11,996 KB
testcase_23 AC 112 ms
10,056 KB
testcase_24 AC 332 ms
33,812 KB
testcase_25 AC 598 ms
42,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;

vector<long long> dijkstra(const Graph &g, int s) {
    vector<long long> dist(g.size(), INF);
    using Pi = pair<long long, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; que.emplace(dist[s], s);
    while (!que.empty()) {
        long long cost; int u; tie(cost, u) = que.top(); que.pop();
        if (dist[u] < cost) continue;
        for (auto &e: g[u]) {
            int v; long long nc; tie(v, nc) = e;
            if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v);
        }
    }
    return dist;
}

int main() {
    int n, m; cin >> n >> m;
    Graph g(n * 2);
    while (m--) {
        int a, b, c; cin >> a >> b >> c; a--, b--;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
        g[a].emplace_back(b + n, 0);
        g[b].emplace_back(a + n, 0);
        g[a + n].emplace_back(b + n, c);
        g[b + n].emplace_back(a + n, c);
    }
    g[0].emplace_back(n, 0);
    g[n].emplace_back(0, 0);
    auto dp = dijkstra(g, 0);
    for (int i = 0; i < n; i++) cout << dp[i] + dp[i + n] << endl;
    return 0;
}
0