# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95407 | dalgerok | Deblo (COCI18_deblo) | C++14 | 186 ms | 17144 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>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, dp[N][2], a[N], b[N], ans, cur;
vector < int > g[N];
void dfs(int v, int pr = -1){
if(b[v]){
cur += 1;
}
dp[v][0] = dp[v][1] = 0;
dp[v][b[v]] += 1;
for(int to : g[v]){
if(to != pr){
dfs(to, v);
cur += dp[v][0] * dp[to][1];
cur += dp[v][1] * dp[to][0];
dp[v][0] += dp[to][b[v]];
dp[v][1] += dp[to][b[v] ^ 1];
}
}
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i < n; i++){
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for(int i = 0; i < 22; i++){
for(int j = 1; j <= n; j++){
b[j] = ((a[j] >> i) & 1);
}
cur = 0;
dfs(1);
ans += (1 << i) * cur;
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |