結果

問題 No.807 umg tours
ユーザー rpy3cpprpy3cpp
提出日時 2019-03-30 23:15:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 293 ms / 4,000 ms
コード長 1,607 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 179,392 KB
実行使用メモリ 43,408 KB
最終ジャッジ日時 2023-08-15 12:17:29
合計ジャッジ時間 6,801 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 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 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 161 ms
32,104 KB
testcase_12 AC 146 ms
24,236 KB
testcase_13 AC 223 ms
33,004 KB
testcase_14 AC 82 ms
15,796 KB
testcase_15 AC 60 ms
13,496 KB
testcase_16 AC 226 ms
34,856 KB
testcase_17 AC 288 ms
41,164 KB
testcase_18 AC 286 ms
41,036 KB
testcase_19 AC 281 ms
38,964 KB
testcase_20 AC 130 ms
22,640 KB
testcase_21 AC 142 ms
23,140 KB
testcase_22 AC 51 ms
11,988 KB
testcase_23 AC 37 ms
9,904 KB
testcase_24 AC 117 ms
32,864 KB
testcase_25 AC 293 ms
43,408 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