# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701714 | scottchou | Deblo (COCI18_deblo) | C++17 | 1087 ms | 11412 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;
int const N = 1e5 + 5;
typedef long long LL;
int a[N];
vector<int> graph[N];
int val[N];
void dfs(int x, int d = 0, int fa = -1){
d = d ^ a[x];
val[x] = d;
for(auto i : graph[x]){
if(i == fa)
continue;
dfs(i, d, x);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int u, v;
LL sum = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
sum += a[i];
}
for(int i = 0; i < n - 1; i++){
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
LL ans = 0;
for(int i = 1; i <= n; i++){
dfs(i);
for(int j = 1; j <= n; j++){
if(i != j)
ans += val[j];
}
}
cout << ans / 2 + sum << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |