Submission #86314

#TimeUsernameProblemLanguageResultExecution timeMemory
86314IvanCDeblo (COCI18_deblo)C++17
90 / 90
296 ms15336 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5 + 10; const int MAXV = 3*1e6 + 10; vector<int> grafo[MAXN]; int valor[MAXN],cor[MAXN],somatorio[MAXN][2],N; ll xor_sum,even_sum; void change(int v,int u,int sinal){ if(cor[v] == 1){ somatorio[v][0] += sinal*somatorio[u][1]; somatorio[v][1] += sinal*somatorio[u][0]; } else{ somatorio[v][1] += sinal*somatorio[u][1]; somatorio[v][0] += sinal*somatorio[u][0]; } } void dfs1(int v,int p){ somatorio[v][0] = somatorio[v][1] = 0; somatorio[v][cor[v]] = 1; for(int u : grafo[v]){ if(u == p) continue; dfs1(u,v); change(v,u,1); } } void dfs2(int v,int p){ even_sum += somatorio[v][1]; for(int u : grafo[v]){ if(u == p) continue; int oldv0 = somatorio[v][0],oldv1 = somatorio[v][1]; // copia // Removendo u de v change(v,u,-1); // Adicionando v a u change(u,v,1); dfs2(u,v); // reverter somatorio[v][0] = oldv0; somatorio[v][1] = oldv1; } } ll query_bit(int k){ for(int i = 1;i<=N;i++){ if(valor[i] & (1 << k)) cor[i] = 1; else cor[i] = 0; } even_sum = 0; dfs1(1,-1); dfs2(1,-1); return (1LL << k)*even_sum; } int main(){ scanf("%d",&N); for(int i = 1;i<=N;i++){ scanf("%d",&valor[i]); } for(int i = 1;i<N;i++){ int a,b; scanf("%d %d",&a,&b); grafo[a].push_back(b); grafo[b].push_back(a); } for(int i = 0;(1 << i) <= MAXV;i++) xor_sum += query_bit(i); for(int i = 1;i<=N;i++) xor_sum -= valor[i]; xor_sum /= 2; for(int i = 1;i<=N;i++) xor_sum += valor[i]; printf("%lld\n",xor_sum); return 0; }

Compilation message (stderr)

deblo.cpp: In function 'int main()':
deblo.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
  ~~~~~^~~~~~~~~
deblo.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&valor[i]);
   ~~~~~^~~~~~~~~~~~~~~~
deblo.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a,&b);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...