結果

問題 No.807 umg tours
ユーザー kyunakyuna
提出日時 2019-10-25 20:30:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 574 ms / 4,000 ms
コード長 1,405 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 90,260 KB
実行使用メモリ 43,744 KB
最終ジャッジ日時 2024-05-03 00:01:33
合計ジャッジ時間 7,439 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 300 ms
32,448 KB
testcase_12 AC 297 ms
24,540 KB
testcase_13 AC 402 ms
33,316 KB
testcase_14 AC 176 ms
16,240 KB
testcase_15 AC 132 ms
13,568 KB
testcase_16 AC 427 ms
35,236 KB
testcase_17 AC 528 ms
41,656 KB
testcase_18 AC 574 ms
41,268 KB
testcase_19 AC 541 ms
39,372 KB
testcase_20 AC 303 ms
22,632 KB
testcase_21 AC 312 ms
23,448 KB
testcase_22 AC 124 ms
12,032 KB
testcase_23 AC 97 ms
10,112 KB
testcase_24 AC 309 ms
34,456 KB
testcase_25 AC 555 ms
43,744 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