結果

問題 No.807 umg tours
ユーザー rpy3cpprpy3cpp
提出日時 2019-03-30 23:15:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 358 ms / 4,000 ms
コード長 1,607 bytes
コンパイル時間 2,059 ms
コンパイル使用メモリ 180,880 KB
実行使用メモリ 42,176 KB
最終ジャッジ日時 2024-05-02 23:43:57
合計ジャッジ時間 7,630 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 194 ms
32,352 KB
testcase_12 AC 181 ms
24,436 KB
testcase_13 AC 258 ms
33,200 KB
testcase_14 AC 97 ms
16,144 KB
testcase_15 AC 70 ms
13,440 KB
testcase_16 AC 272 ms
35,140 KB
testcase_17 AC 358 ms
40,904 KB
testcase_18 AC 349 ms
41,028 KB
testcase_19 AC 334 ms
39,248 KB
testcase_20 AC 165 ms
22,512 KB
testcase_21 AC 171 ms
23,296 KB
testcase_22 AC 60 ms
11,904 KB
testcase_23 AC 45 ms
9,984 KB
testcase_24 AC 132 ms
32,708 KB
testcase_25 AC 345 ms
42,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr long long INF = 1'000'000'000'000'000'000L;

struct Edge{
    int to;
    long long cost;
    Edge(int to, long long cost):to(to), cost(cost) {}
};


vector<long long> dijkstra(int start, const vector<vector<Edge>> &Es){
    int N = Es.size();
    vector<long long> dist(N, INF);
    dist[start] = 0;
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<>> pq;
    pq.push(make_pair(0, start));
    while (not pq.empty()){
        long long d;
        int v;
        tie(d, v) = pq.top();
        pq.pop();
        if (d > dist[v]) continue;
        dist[v] = d;
        for (auto &uc : Es[v]){
            int u = uc.to;
            long long new_d = d + uc.cost;
            if (new_d < dist[u]){
                dist[u] = new_d;
                pq.push(make_pair(new_d, u));
            }
        }
    }
    return dist;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<Edge>> Es(2 * N, vector<Edge>());
    for (int m = 0; m != M; ++m){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        --a;
        --b;
        Es[a].emplace_back(Edge(b, c));
        Es[b].emplace_back(Edge(a, c));
        Es[a].emplace_back(Edge(N + b, 0));
        Es[b].emplace_back(Edge(N + a, 0));
        Es[N + a].emplace_back(Edge(N + b, c));
        Es[N + b].emplace_back(Edge(N + a, c));
    }
    auto dist = dijkstra(0, Es);
    dist[N] = 0;
    for (int i = 0; i < N; ++i){
        cout << dist[i] + dist[i + N] << '\n';
    }
    return 0;
}
0