結果

問題 No.807 umg tours
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-05-17 12:03:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,757 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 92,456 KB
実行使用メモリ 814,492 KB
最終ジャッジ日時 2023-10-17 07:14:49
合計ジャッジ時間 3,215 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<tuple>
#include<limits>

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<long>> costs(n, std::vector<long>(n, -1));
    int a, b;
    long c;
    for (int i = 0; i < m; i++) {
        std::cin >> a >> b >> c;

        a--;
        b--;
        costs[a][b] = c;
        costs[b][a] = c;
    }

    std::vector<long> d2(n, std::numeric_limits<long>::max()); // NOT SKIPPED
    std::vector<long> d3(n, std::numeric_limits<long>::max()); // SKIPPED
    std::priority_queue<std::tuple<long, int, bool>> q2;
    d2[0] = 0;
    d3[0] = 0;
    q2.push(std::make_tuple(0, 0, false));
    q2.push(std::make_tuple(0, 0, true));

    while (!q2.empty()) {
        auto [_, u, skipped] = q2.top();
        q2.pop();
        
        if (skipped) {
            for (int v = 0; v < n; v++) {
                if (costs[u][v] == -1) {
                    continue;
                }

                if (d3[u] + costs[u][v] < d3[v]) {
                    d3[v] = d3[u] + costs[u][v];
                    q2.push(std::make_tuple(d3[v], v, true));
                }
            }
        } else {
            for (int v = 0; v < n; v++) {
                if (costs[u][v] == -1) {
                    continue;
                }

                if (d2[u] + costs[u][v] < d2[v]) {
                    d2[v] = d2[u] + costs[u][v];
                    q2.push(std::make_tuple(d2[v], v, false));
                }

                if (d2[u] < d3[v]) {
                    d3[v] = d2[u];
                    q2.push(std::make_tuple(d3[v], v, true));
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        std::cout << d2[i] + d3[i] << std::endl;
    }
}
0