結果

問題 No.2377 SUM AND XOR on Tree
ユーザー karinohitokarinohito
提出日時 2023-07-07 22:47:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 820 ms / 4,000 ms
コード長 1,192 bytes
コンパイル時間 4,419 ms
コンパイル使用メモリ 270,480 KB
実行使用メモリ 24,252 KB
最終ジャッジ日時 2023-09-29 00:22:28
合計ジャッジ時間 18,474 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 673 ms
15,548 KB
testcase_09 AC 691 ms
15,556 KB
testcase_10 AC 714 ms
15,720 KB
testcase_11 AC 688 ms
15,592 KB
testcase_12 AC 762 ms
15,716 KB
testcase_13 AC 762 ms
15,452 KB
testcase_14 AC 691 ms
15,080 KB
testcase_15 AC 744 ms
15,456 KB
testcase_16 AC 744 ms
14,900 KB
testcase_17 AC 757 ms
15,212 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 820 ms
15,720 KB
testcase_24 AC 784 ms
15,492 KB
testcase_25 AC 799 ms
15,500 KB
testcase_26 AC 253 ms
24,204 KB
testcase_27 AC 253 ms
24,212 KB
testcase_28 AC 252 ms
24,252 KB
testcase_29 AC 173 ms
15,448 KB
testcase_30 AC 172 ms
15,572 KB
testcase_31 AC 174 ms
15,620 KB
testcase_32 AC 231 ms
15,616 KB
testcase_33 AC 224 ms
15,496 KB
testcase_34 AC 234 ms
15,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using mint = modint998244353;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
#define rep(i,n) for(ll i=(ll)(0); i<(ll(n)); ++i)
#define all(x) (x).begin(), (x).end()

vll A;
vvll G;
vector<vector<mint>> P;
void dfs(ll n, ll p, ll d) {
    if (A[n] & (1ll << d))P[n][1] = 1;
    else P[n][0] = 1;
    for (auto v : G[n]) {
        if (v != p) {
            dfs(v, n, d);
            mint a = P[n][0] * (P[v][0] + P[v][1]) + P[v][1] * P[n][1];
            mint b= P[n][1] * (P[v][0] + P[v][1]) + P[v][1] * P[n][0];
            P[n][1] = b;
            P[n][0] = a;

            
        }
    }
}

int main() {
    ll N;
    cin >> N;
    G.resize(N);
    rep(i, N - 1) {
        ll U, V;
        cin >> U >> V;
        U--; V--;
        G[U].push_back(V);
        G[V].push_back(U);
    }
    A.resize(N);
    rep(i, N)cin >> A[i];
    mint an = 0;
    rep(b, 31) {
        P.assign(N, vector<mint>(2, 0));
        dfs(0, -1, b);
        an += (P[0][1]*(1ll<<b));
    }
    cout << an.val() << endl;
}
0