Submission #527883

#TimeUsernameProblemLanguageResultExecution timeMemory
527883aris12345678Deblo (COCI18_deblo)C++14
63 / 90
50 ms8436 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mxN = 1e5+5; vector<int> adj[mxN]; int a[mxN], pref[mxN]; ll res[mxN]; void bfs(int s) { queue<int> q; res[s] = a[s]; q.push(s); while(!q.empty()) { int u = q.front(); q.pop(); for(auto &v : adj[u]) { if(res[v] == -1) { res[v] = 1LL*res[u]^a[v]; q.push(v); } } } } int main() { int n; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &a[i]); for(int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); adj[u-1].push_back(v-1); adj[v-1].push_back(u-1); } ll ans = 0; if(n <= 1000) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) res[j] = -1; bfs(i); for(int j = i; j < n; j++) ans += res[j]; } } else { pref[0] = a[0]; for(int i = 1; i < n; i++) pref[i] = pref[i-1]^a[i]; for(int i = 0; i <= 30; i++) { ll zeros = 1LL, ones = 0LL, ithset = 0LL; for(int j = 0; j < n; j++) { if((1<<i)&pref[j]) ithset += zeros, ones++; else ithset += ones, zeros++; } ll add = (1LL<<i)*ithset; ans += add; } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

deblo.cpp: In function 'int main()':
deblo.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
deblo.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
deblo.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...