結果

問題 No.2377 SUM AND XOR on Tree
ユーザー 259-Momone259-Momone
提出日時 2024-03-19 22:08:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 469 ms / 4,000 ms
コード長 1,434 bytes
コンパイル時間 4,215 ms
コンパイル使用メモリ 327,720 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-03-19 22:08:40
合計ジャッジ時間 15,217 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 445 ms
9,344 KB
testcase_09 AC 439 ms
9,344 KB
testcase_10 AC 459 ms
9,344 KB
testcase_11 AC 430 ms
9,344 KB
testcase_12 AC 451 ms
9,344 KB
testcase_13 AC 435 ms
9,344 KB
testcase_14 AC 450 ms
9,088 KB
testcase_15 AC 469 ms
9,216 KB
testcase_16 AC 443 ms
9,088 KB
testcase_17 AC 401 ms
9,216 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 407 ms
9,344 KB
testcase_24 AC 438 ms
9,344 KB
testcase_25 AC 405 ms
9,344 KB
testcase_26 AC 165 ms
13,056 KB
testcase_27 AC 167 ms
13,056 KB
testcase_28 AC 165 ms
13,056 KB
testcase_29 AC 129 ms
9,588 KB
testcase_30 AC 128 ms
9,588 KB
testcase_31 AC 128 ms
9,588 KB
testcase_32 AC 142 ms
9,216 KB
testcase_33 AC 142 ms
9,216 KB
testcase_34 AC 144 ms
9,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <bits/extc++.h>

template <int m>
std::ostream &operator<<(std::ostream &os, const atcoder::static_modint<m> &mint) {
    os << mint.val();
    return os;
}

template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) {
    os << "[" << p.first << " " << p.second << "]";
    return os;
}

int main() {
    using namespace std;
    using modint = atcoder::static_modint<998244353>;
    unsigned N;
    cin >> N;
    vector<vector<unsigned>> edges(N);
    for (unsigned i{1}, u, v; i < N; ++i) {
        cin >> u >> v;
        edges[--u].emplace_back(--v);
        edges[v].emplace_back(u);
    }

    vector<unsigned> A(N);
    for (auto &&a : A)
        cin >> a;

    modint ans{};
    for (unsigned i{30}; i--;) {
        (ans *= 2) += [dfs_impl{[&edges, &A, &i](const auto &f, unsigned now, unsigned prev) -> pair<modint, modint> {
            pair<modint, modint> ans{!(1 & (A[now] >> i)), 1 & (A[now] >> i)};
            auto &&[z, o]{ans};

            for (const auto &next : edges[now])
                if (next != prev) {
                    const auto &[zero, one]{f(f, next, now)};
                    ans = make_pair(z * (zero + one) + o * one, o * (zero + one) + z * one);
                }
            return ans;
        }}] {
            return dfs_impl(dfs_impl, 0, 0).second;
        }();
    }

    cout << ans.val() << endl;
    return 0;
}
0