답안 #778620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778620 2023-07-10T13:40:21 Z DangerNoodle7591 Deblo (COCI18_deblo) C++17
18 / 90
72 ms 33824 KB
#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define ll long long
#define pb push_back
#define N 100001
#define M 23
vector<int> adj[N];
int dp[N][M][2],arr[N];
ll int cev=0;
void dfs(int x,int once){
	for(int i=0;i<M;i++){
		if((arr[x]>>i)&1)dp[x][i][0]=1;
		else dp[x][i][1]=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;
		}
	}
}
int 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;

}






# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2672 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Incorrect 2 ms 2900 KB Output isn't correct
5 Incorrect 2 ms 2900 KB Output isn't correct
6 Incorrect 49 ms 33784 KB Output isn't correct
7 Incorrect 49 ms 33824 KB Output isn't correct
8 Incorrect 52 ms 27112 KB Output isn't correct
9 Incorrect 72 ms 26724 KB Output isn't correct
10 Incorrect 70 ms 26016 KB Output isn't correct