結果

問題 No.807 umg tours
ユーザー kyunakyuna
提出日時 2019-10-26 18:55:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 609 ms / 4,000 ms
コード長 1,376 bytes
コンパイル時間 1,032 ms
コンパイル使用メモリ 89,728 KB
実行使用メモリ 42,952 KB
最終ジャッジ日時 2023-08-15 12:34:14
合計ジャッジ時間 8,667 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,388 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 336 ms
32,192 KB
testcase_12 AC 341 ms
24,316 KB
testcase_13 AC 468 ms
33,040 KB
testcase_14 AC 190 ms
15,860 KB
testcase_15 AC 148 ms
13,364 KB
testcase_16 AC 483 ms
35,036 KB
testcase_17 AC 603 ms
42,224 KB
testcase_18 AC 605 ms
41,756 KB
testcase_19 AC 608 ms
39,100 KB
testcase_20 AC 347 ms
22,404 KB
testcase_21 AC 365 ms
23,188 KB
testcase_22 AC 147 ms
11,820 KB
testcase_23 AC 111 ms
10,096 KB
testcase_24 AC 324 ms
33,328 KB
testcase_25 AC 609 ms
42,952 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);
    auto dp = dijkstra(g, 0);
    for (int i = 0; i < n; i++) cout << dp[i] + dp[i + n] << endl;
    return 0;
}
0