# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
228946 | VEGAnn | Deblo (COCI18_deblo) | C++14 | 191 ms | 31224 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 PB push_back
using namespace std;
typedef long long ll;
const int N = 100100;
const int PW = 22;
ll ans = 0;
vector<int> g[N];
int n, vl[N], kol[2][PW][N];
void dfs(int v, int p){
ans += vl[v];
for (int po = 0; po < PW; po++)
kol[bool(vl[v] & (1 << po))][po][v]++;
for (int u : g[v]){
if (u == p) continue;
dfs(u, v);
for (int po = 0; po < PW; po++){
ans += (1ll << po) * kol[0][po][v] * kol[1][po][u];
ans += (1ll << po) * kol[1][po][v] * kol[0][po][u];
int bt = bool(vl[v] & (1 << po));
kol[0][po][v] += kol[bt][po][u];
kol[1][po][v] += kol[bt ^ 1][po][u];
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> vl[i];
for (int i = 1; i < n; i++){
int x, y; cin >> x >> y;
x--; y--;
g[x].PB(y);
g[y].PB(x);
}
dfs(0, -1);
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |