結果

問題 No.807 umg tours
ユーザー mencottonmencotton
提出日時 2020-11-02 21:46:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,509 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 80,536 KB
実行使用メモリ 26,992 KB
最終ジャッジ日時 2023-09-29 13:48:56
合計ジャッジ時間 8,205 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,504 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 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 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 260 ms
18,880 KB
testcase_12 AC 222 ms
16,424 KB
testcase_13 AC 328 ms
21,196 KB
testcase_14 AC 124 ms
11,340 KB
testcase_15 AC 93 ms
9,628 KB
testcase_16 AC 343 ms
22,216 KB
testcase_17 AC 425 ms
26,304 KB
testcase_18 AC 434 ms
26,252 KB
testcase_19 AC 414 ms
25,448 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 175 ms
20,840 KB
testcase_25 AC 422 ms
26,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

struct edge {
    int to;
    int cost;
};

struct status {
    int cost;
    int v;

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

const int INF = (1 << 30) - 1;

vector<int> dijkstra(int s, int n, vector<vector<edge>> &graph) {
    priority_queue<status, vector<status>, greater<>> que;
    vector<int> 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<int> 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