Submission #778630

# Submission time Handle Problem Language Result Execution time Memory
778630 2023-07-10T13:49:00 Z DangerNoodle7591 Deblo (COCI18_deblo) C++17
90 / 90
86 ms 56660 KB
#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define pb push_back
#define N 100005
#define M 26
vector<int> adj[N];
int dp[N][M][2],arr[N];
int cev=0;
void dfs(int x,int once){
	for(int i=0;i<M;i++){
		if((arr[x]>>i)&1)dp[x][i][1]=1;
		else dp[x][i][0]=1;
	}
	for(auto u:adj[x]){
		if(u==once)continue;
		dfs(u,x);
		for(int i=0;i<M;i++){
			int a=dp[u][i][0],b=dp[u][i][1];
			int top=(dp[x][i][0]*b+dp[x][i][1]*a);
			cev+=(top<<i);
			int k=(arr[x]>>i)&1;
			dp[x][i][k]+=a;
			dp[x][i][k^1]+=b;
		}
	}
}
signed main(){
	lalala;
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
		cev+=arr[i];
	}
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		adj[a].pb(b);adj[b].pb(a);
	}
	dfs(1,-1);
	cout<<cev<<endl;
 
}






# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 3116 KB Output is correct
5 Correct 3 ms 3028 KB Output is correct
6 Correct 62 ms 56660 KB Output is correct
7 Correct 63 ms 56660 KB Output is correct
8 Correct 62 ms 49356 KB Output is correct
9 Correct 64 ms 48588 KB Output is correct
10 Correct 86 ms 47776 KB Output is correct