Submission #86986

#TimeUsernameProblemLanguageResultExecution timeMemory
86986joseacazDeblo (COCI18_deblo)C++17
45 / 90
1085 ms15692 KiB
#include <bits/stdc++.h> #define MAXN 100005 using namespace std; typedef long long ll; ll N, val[MAXN], u, v, vis[MAXN], ans; vector < ll > Graph[MAXN]; void clear () { for ( ll i = 1; i <= N; i++ ) vis[i] = 0; } void solve ( ll start, ll node, ll v ) { if ( node >= start ) ans += v; vis[node] = 1; for ( auto i : Graph[node] ) if ( !vis[i] ) solve ( start, i, v ^ val[i] ); } int main() { cin >> N; for ( ll i = 1; i <= N; i++ ) cin >> val[i]; for ( ll i = 0; i < N - 1; i++ ) { cin >> u >> v; Graph[u].push_back ( v ); Graph[v].push_back ( u ); } for ( ll i = 1; i <= N; i++ ) { clear(); solve ( i, i, val[i] ); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...