結果
問題 | No.2377 SUM AND XOR on Tree |
ユーザー | Kude |
提出日時 | 2023-07-07 22:32:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 471 ms / 4,000 ms |
コード長 | 1,544 bytes |
コンパイル時間 | 2,513 ms |
コンパイル使用メモリ | 227,016 KB |
実行使用メモリ | 18,348 KB |
最終ジャッジ日時 | 2023-09-29 00:00:21 |
合計ジャッジ時間 | 11,908 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 455 ms
9,064 KB |
testcase_09 | AC | 471 ms
9,112 KB |
testcase_10 | AC | 467 ms
9,168 KB |
testcase_11 | AC | 382 ms
9,056 KB |
testcase_12 | AC | 416 ms
9,108 KB |
testcase_13 | AC | 423 ms
9,176 KB |
testcase_14 | AC | 311 ms
8,908 KB |
testcase_15 | AC | 441 ms
8,852 KB |
testcase_16 | AC | 402 ms
8,792 KB |
testcase_17 | AC | 425 ms
8,916 KB |
testcase_18 | AC | 2 ms
4,380 KB |
testcase_19 | AC | 2 ms
4,380 KB |
testcase_20 | AC | 2 ms
4,376 KB |
testcase_21 | AC | 2 ms
4,376 KB |
testcase_22 | AC | 2 ms
4,376 KB |
testcase_23 | AC | 407 ms
9,052 KB |
testcase_24 | AC | 421 ms
9,112 KB |
testcase_25 | AC | 391 ms
9,292 KB |
testcase_26 | AC | 127 ms
18,348 KB |
testcase_27 | AC | 135 ms
18,344 KB |
testcase_28 | AC | 128 ms
18,304 KB |
testcase_29 | AC | 104 ms
9,360 KB |
testcase_30 | AC | 103 ms
9,428 KB |
testcase_31 | AC | 104 ms
9,488 KB |
testcase_32 | AC | 111 ms
8,852 KB |
testcase_33 | AC | 110 ms
9,100 KB |
testcase_34 | AC | 112 ms
8,916 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using mint = modint998244353; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VVI to(n); rep(_, n - 1) { int u, v; cin >> u >> v; u--, v--; to[u].emplace_back(v); to[v].emplace_back(u); } VI a(n); rep(i, n) cin >> a[i]; mint ans; rep(k, 30) { using A = array<mint, 2>; auto dfs = [&](auto&& self, int u, int p) -> A { A res; res[a[u] >> k & 1] = 1; for(int v: to[u]) if (v != p) { A r = self(self, v, u); A nres; // non-cut rep(i, 2) rep(j, 2) nres[i ^ j] += res[i] * r[j]; // cut rep(i, 2) nres[i] += res[i] * r[1]; res = nres; } return res; }; A res = dfs(dfs, 0, -1); ans += res[1] * mint(2).pow(k); } cout << ans.val() << '\n'; }