結果
問題 | No.2377 SUM AND XOR on Tree |
ユーザー |
|
提出日時 | 2024-03-19 22:08:24 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 234 ms / 4,000 ms |
コード長 | 1,434 bytes |
コンパイル時間 | 3,665 ms |
コンパイル使用メモリ | 326,952 KB |
実行使用メモリ | 13,056 KB |
最終ジャッジ日時 | 2024-09-30 05:48:29 |
合計ジャッジ時間 | 10,094 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
#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;}