結果

問題 No.807 umg tours
ユーザー mencottonmencotton
提出日時 2020-11-02 21:47:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 4,000 ms
コード長 1,527 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 81,288 KB
実行使用メモリ 42,460 KB
最終ジャッジ日時 2023-09-29 13:49:35
合計ジャッジ時間 6,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 219 ms
32,040 KB
testcase_12 AC 175 ms
24,428 KB
testcase_13 AC 254 ms
32,900 KB
testcase_14 AC 103 ms
15,952 KB
testcase_15 AC 75 ms
13,352 KB
testcase_16 AC 271 ms
34,880 KB
testcase_17 AC 338 ms
42,124 KB
testcase_18 AC 334 ms
41,248 KB
testcase_19 AC 334 ms
39,108 KB
testcase_20 AC 157 ms
22,532 KB
testcase_21 AC 163 ms
23,184 KB
testcase_22 AC 65 ms
11,852 KB
testcase_23 AC 48 ms
9,972 KB
testcase_24 AC 156 ms
30,508 KB
testcase_25 AC 343 ms
42,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using ll = long long;

struct edge {
    int to;
    ll cost;
};

struct status {
    ll cost;
    int v;

    bool operator<(const status &rhs) const { return cost < rhs.cost; };
    bool operator>(const status &rhs) const { return cost > rhs.cost; };
};

const ll INF = (1LL << 60) - 1;

vector<ll> dijkstra(int s, int n, vector<vector<edge>> &graph) {
    priority_queue<status, vector<status>, greater<>> que;
    vector<ll> dis(n, INF);
    dis[s] = 0;
    que.push({0, s});

    while (!que.empty()) {
        status now = que.top();
        que.pop();

        if (dis[now.v] < now.cost)continue;

        for (auto next:graph[now.v]) {
            if (dis[next.to] > dis[now.v] + next.cost) {
                dis[next.to] = dis[now.v] + next.cost;
                que.push({dis[next.to], next.to});
            }
        }
    }

    return dis;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge>> graph(n * 2);
    for (int i = 0; i < m; i++) {
        int u, v, cost;
        cin >> u >> v >> cost, u--, v--;
        graph[u].push_back({v, cost}), graph[v].push_back({u, cost});
        graph[u].push_back({v + n, 0}), graph[v].push_back({u + n, 0});
        graph[u + n].push_back({v + n, cost}), graph[v + n].push_back({u + n, cost});
    }

    vector<ll> dis = dijkstra(0, n * 2, graph);
    cout << 0 << endl;
    for (int i = 1; i < n; i++) cout << dis[i] + dis[i + n] << "\n";
    cout << flush;
    return 0;
}
0