# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92152 | Kastanda | Deblo (COCI18_deblo) | C++11 | 212 ms | 13816 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;
const int N = 100005;
int n, A[N], C[N][2];
long long tot, cnt;
bool B[N];
vector < int > Adj[N];
void DFS(int v, int p)
{
if (B[v]) cnt ++;
C[v][0] = C[v][1] = 0;
C[v][B[v]] ++;
for (int &u : Adj[v])
if (u != p)
{
DFS(u, v);
cnt += 1LL * C[v][0] * C[u][1];
cnt += 1LL * C[v][1] * C[u][0];
C[v][0] += C[u][B[v]];
C[v][1] += C[u][!B[v]];
}
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &A[i]);
for (int i = 1, v, u; i < n; i++)
scanf("%d%d", &v, &u),
Adj[v].push_back(u),
Adj[u].push_back(v);
for (int j = 0; j <= 21; j++)
{
cnt = 0;
for (int i = 1; i <= n; i++)
B[i] = (A[i] >> j) & 1;
DFS(1, 0);
tot += cnt * (1LL << j);
}
return !printf("%lld", tot);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |