# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116623 | nandonathaniel | Deblo (COCI18_deblo) | C++14 | 243 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAXN=100005;
const LL LOG=22;
LL a[MAXN],bit[MAXN][LOG],val[MAXN][LOG][2],ans[LOG];
vector<LL> adj[MAXN];
void dfs(LL now,LL par){
for(LL i=0;i<LOG;i++){
val[now][i][bit[now][i]]++;
ans[i]+=bit[now][i];
}
for(auto nxt : adj[now]){
if(nxt==par)continue;
dfs(nxt,now);
for(LL i=0;i<LOG;i++){
ans[i]+=val[nxt][i][0]*val[now][i][1];
ans[i]+=val[nxt][i][1]*val[now][i][0];
val[now][i][0]+=val[nxt][i][bit[now][i]];
val[now][i][1]+=val[nxt][i][!bit[now][i]];
}
}
}
int main(){
LL n,u,v;
cin >> n;
for(LL i=1;i<=n;i++){
cin >> a[i];
for(int j=0;j<LOG;j++){
if(a[i] & (1<<j))bit[i][j]=1;
}
}
for(LL i=1;i<n;i++){
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1,-1);
LL ret=0;
for(LL i=0;i<LOG;i++){
ret+=((1<<i)*ans[i]);
}
cout << ret << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |