結果

問題 No.2377 SUM AND XOR on Tree
ユーザー 沙耶花沙耶花
提出日時 2023-07-10 19:23:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 954 ms / 4,000 ms
コード長 1,025 bytes
コンパイル時間 4,815 ms
コンパイル使用メモリ 268,392 KB
実行使用メモリ 29,084 KB
最終ジャッジ日時 2023-10-10 01:21:40
合計ジャッジ時間 22,930 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 785 ms
14,972 KB
testcase_09 AC 807 ms
14,928 KB
testcase_10 AC 841 ms
14,920 KB
testcase_11 AC 810 ms
15,096 KB
testcase_12 AC 858 ms
15,264 KB
testcase_13 AC 954 ms
14,968 KB
testcase_14 AC 786 ms
14,520 KB
testcase_15 AC 904 ms
14,792 KB
testcase_16 AC 821 ms
14,520 KB
testcase_17 AC 842 ms
14,660 KB
testcase_18 AC 3 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 744 ms
15,032 KB
testcase_24 AC 843 ms
14,992 KB
testcase_25 AC 799 ms
15,044 KB
testcase_26 AC 369 ms
29,084 KB
testcase_27 AC 372 ms
28,904 KB
testcase_28 AC 378 ms
29,080 KB
testcase_29 AC 289 ms
15,316 KB
testcase_30 AC 296 ms
15,272 KB
testcase_31 AC 296 ms
15,572 KB
testcase_32 AC 388 ms
15,020 KB
testcase_33 AC 383 ms
15,016 KB
testcase_34 AC 379 ms
14,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
int n;
vector<vector<int>> E;
vector<int> b;
vector<vector<mint>> dp;
void dfs(int cv,int pv){
	vector<mint> tdp(2,0);
	tdp[b[cv]] = 1;
	rep(i,E[cv].size()){
		int to = E[cv][i];
		if(to==pv)continue;
		dfs(to,cv);
		vector<mint> ndp(2,0);
		rep(j,2){
			rep(k,2){
				ndp[j^k] += tdp[j] * dp[to][k];
				if(k==1){
					ndp[j] += tdp[j] * dp[to][k];
				}
			}
		}
		swap(tdp,ndp);
	}	
	dp[cv] = tdp;
}

int main(){
	cin>>n;
	E.resize(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	mint ans = 0;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	b.resize(n);
	rep(i,30){
		rep(j,n)b[j] = (a[j]>>i)&1;
		dp.assign(n,vector<mint>(2,0));
		dfs(0,-1);
		ans += dp[0][1] * mint(2).pow(i);
		
	}
	
	cout<<ans.val()<<endl;
	
	
	return 0;
}
0