Submission #701714

#TimeUsernameProblemLanguageResultExecution timeMemory
701714scottchouDeblo (COCI18_deblo)C++17
45 / 90
1087 ms11412 KiB
#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 timeMemoryGrader output
Fetching results...