結果

問題 No.807 umg tours
ユーザー kyunakyuna
提出日時 2019-10-26 18:55:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 525 ms / 4,000 ms
コード長 1,376 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 90,280 KB
実行使用メモリ 43,232 KB
最終ジャッジ日時 2024-05-03 00:02:39
合計ジャッジ時間 7,507 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 291 ms
32,412 KB
testcase_12 AC 280 ms
24,512 KB
testcase_13 AC 397 ms
33,308 KB
testcase_14 AC 161 ms
16,240 KB
testcase_15 AC 129 ms
13,568 KB
testcase_16 AC 445 ms
35,236 KB
testcase_17 AC 525 ms
41,144 KB
testcase_18 AC 514 ms
41,016 KB
testcase_19 AC 521 ms
39,368 KB
testcase_20 AC 302 ms
22,656 KB
testcase_21 AC 323 ms
23,412 KB
testcase_22 AC 126 ms
12,032 KB
testcase_23 AC 95 ms
10,112 KB
testcase_24 AC 306 ms
33,908 KB
testcase_25 AC 521 ms
43,232 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