提出 #73341954


ソースコード 拡げる

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<sys/time.h>
// #include<atcoder/segtree>
// #include<atcoder/modint>

using namespace std;

// using mint = atcoder::modint998244353;

using P = pair<int, int>;
const int M = 998244353;
const long long LM = 1LL << 60;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<vector<P>> edge(n);
    for (int i = 0; i < m; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        --u;
        --v;
        edge[u].emplace_back(w, v);
        edge[v].emplace_back(w, u);
    }
    vector<vector<int>> dist(2, vector<int>(n, 1 << 30));
    priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> pq;
    dist[0][0] = 1;
    pq.push({ dist[0][0], { 0, 0 } });

    auto f = [](int x, int w) {
        if ((x | w) == w) {
            return x;
        }
        for (int i = 0; i < 30; ++i) {
            if (((x >> i) & 1) == 0) {
                auto y = (x | (1 << i)) & ~((1 << i) - 1);
                if ((y | w) == w) {
                    return y;
                }
            }
        }
        return 1 << 30;
    };


    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();
        if (dist[p.second.first][p.second.second] != p.first) {
            continue;
        }
        for (auto&& e : edge[p.second.second]) {
            auto nj = e.second;
            auto ni = p.second.first || e.second == n - 1;
            auto nv = f(p.first, e.first);
            if (dist[ni][nj] > nv) {
                dist[ni][nj] = nv;
                pq.push({ dist[ni][nj], { ni, nj } });
            }
        }
    }
    int mi = dist[1][n - 1];
    int ma = mi;
    if (mi == (1 << 30)) {
        cout << "-1 -1\n";
        return 0;
    }

    for (int i = 0; i < n - 1; ++i) {
        for (auto&& e : edge[i]) {
            if (e.second == n - 1) {
                if (dist[0][i] <= e.first) {
                    ma = max(ma, e.first);
                }
            }
        }
    }
    cout << mi << ' ' << ma << '\n';

    return 0;
}

提出情報

提出日時
問題 H - Takosan Takusan
ユーザ riantkb
言語 C++23 (GCC 15.2.0)
得点 100
コード長 2252 Byte
結果 AC
実行時間 139 ms
メモリ 25180 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 100 / 100
結果
AC × 3
AC × 61
セット名 テストケース
Sample 01_example_01, 01_example_02, 01_example_03
All 01_example_01, 01_example_02, 01_example_03, 02_random_01, 02_random_02, 02_random_03, 02_random_04, 02_random_05, 02_random_06, 02_random_07, 02_random_08, 02_random_09, 02_random_10, 03_max_01, 03_max_02, 03_max_03, 03_max_04, 03_max_05, 03_max_06, 03_max_07, 03_max_08, 03_max_09, 03_max_10, 03_max_11, 03_max_12, 03_max_13, 03_max_14, 03_max_15, 03_max_16, 03_max_17, 03_max_18, 03_max_19, 03_max_20, 03_max_21, 03_max_22, 03_max_23, 03_max_24, 03_max_25, 03_max_26, 03_max_27, 03_max_28, 03_max_29, 03_max_30, 04_tree_01, 04_tree_02, 04_tree_03, 04_tree_04, 04_tree_05, 05_path_01, 05_path_02, 05_path_03, 05_path_04, 05_path_05, 06_star_01, 06_star_02, 06_star_03, 06_star_04, 06_star_05, 07_corner_01, 07_corner_02, 07_corner_03
ケース名 結果 実行時間 メモリ
01_example_01 AC 1 ms 3680 KiB
01_example_02 AC 1 ms 3684 KiB
01_example_03 AC 1 ms 3544 KiB
02_random_01 AC 103 ms 13820 KiB
02_random_02 AC 64 ms 9956 KiB
02_random_03 AC 77 ms 12092 KiB
02_random_04 AC 139 ms 16808 KiB
02_random_05 AC 66 ms 17228 KiB
02_random_06 AC 57 ms 12252 KiB
02_random_07 AC 35 ms 8764 KiB
02_random_08 AC 96 ms 12588 KiB
02_random_09 AC 91 ms 17012 KiB
02_random_10 AC 50 ms 8352 KiB
03_max_01 AC 61 ms 17512 KiB
03_max_02 AC 61 ms 17564 KiB
03_max_03 AC 60 ms 17488 KiB
03_max_04 AC 61 ms 17740 KiB
03_max_05 AC 61 ms 17624 KiB
03_max_06 AC 60 ms 17652 KiB
03_max_07 AC 60 ms 17632 KiB
03_max_08 AC 61 ms 17632 KiB
03_max_09 AC 59 ms 17512 KiB
03_max_10 AC 61 ms 17624 KiB
03_max_11 AC 61 ms 17464 KiB
03_max_12 AC 61 ms 17488 KiB
03_max_13 AC 60 ms 17636 KiB
03_max_14 AC 60 ms 17632 KiB
03_max_15 AC 59 ms 17612 KiB
03_max_16 AC 59 ms 17612 KiB
03_max_17 AC 61 ms 17632 KiB
03_max_18 AC 58 ms 17560 KiB
03_max_19 AC 61 ms 17516 KiB
03_max_20 AC 63 ms 17624 KiB
03_max_21 AC 61 ms 17516 KiB
03_max_22 AC 60 ms 17744 KiB
03_max_23 AC 56 ms 17744 KiB
03_max_24 AC 56 ms 17740 KiB
03_max_25 AC 57 ms 17508 KiB
03_max_26 AC 57 ms 17480 KiB
03_max_27 AC 57 ms 17612 KiB
03_max_28 AC 57 ms 17564 KiB
03_max_29 AC 56 ms 17516 KiB
03_max_30 AC 57 ms 17560 KiB
04_tree_01 AC 42 ms 13512 KiB
04_tree_02 AC 39 ms 13336 KiB
04_tree_03 AC 59 ms 17616 KiB
04_tree_04 AC 57 ms 17616 KiB
04_tree_05 AC 56 ms 17516 KiB
05_path_01 AC 38 ms 11232 KiB
05_path_02 AC 41 ms 11364 KiB
05_path_03 AC 77 ms 16612 KiB
05_path_04 AC 40 ms 13548 KiB
05_path_05 AC 54 ms 16588 KiB
06_star_01 AC 76 ms 15992 KiB
06_star_02 AC 93 ms 19100 KiB
06_star_03 AC 136 ms 25136 KiB
06_star_04 AC 128 ms 21964 KiB
06_star_05 AC 134 ms 25180 KiB
07_corner_01 AC 1 ms 3608 KiB
07_corner_02 AC 1 ms 3604 KiB
07_corner_03 AC 1 ms 3680 KiB