Submission #95407

#TimeUsernameProblemLanguageResultExecution timeMemory
95407dalgerokDeblo (COCI18_deblo)C++14
90 / 90
186 ms17144 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 5; int n, dp[N][2], a[N], b[N], ans, cur; vector < int > g[N]; void dfs(int v, int pr = -1){ if(b[v]){ cur += 1; } dp[v][0] = dp[v][1] = 0; dp[v][b[v]] += 1; for(int to : g[v]){ if(to != pr){ dfs(to, v); cur += dp[v][0] * dp[to][1]; cur += dp[v][1] * dp[to][0]; dp[v][0] += dp[to][b[v]]; dp[v][1] += dp[to][b[v] ^ 1]; } } } main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i < n; i++){ int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } for(int i = 0; i < 22; i++){ for(int j = 1; j <= n; j++){ b[j] = ((a[j] >> i) & 1); } cur = 0; dfs(1); ans += (1 << i) * cur; } cout << ans; }

Compilation message (stderr)

deblo.cpp:31:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  main(){
       ^
#Verdict Execution timeMemoryGrader output
Fetching results...