Submission #305500

#TimeUsernameProblemLanguageResultExecution timeMemory
305500phathnvDeblo (COCI18_deblo)C++11
90 / 90
161 ms33120 KiB
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "Deblo" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int N = 1e5 + 1; const int logV = 22; int n, a[N]; vector <int> adj[N]; int cnt[N][logV][2]; ll res[logV]; void readInput(){ scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i < n; i++){ int u, v; scanf("%d %d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } } void dfs(int u, int p){ for(int i = 0; i < logV; i++){ int bit = (a[u] >> i) & 1; cnt[u][i][bit]++; if (bit) res[i]++; } for(int v : adj[u]) if (v != p){ dfs(v, u); for(int i = 0; i < logV; i++){ res[i] += (ll) cnt[u][i][1] * cnt[v][i][0]; res[i] += (ll) cnt[u][i][0] * cnt[v][i][1]; int bit = (a[u] >> i) & 1; cnt[u][i][0] += cnt[v][i][0 ^ bit]; cnt[u][i][1] += cnt[v][i][1 ^ bit]; } } } void solve(){ dfs(1, -1); ll ans = 0; for(int i = 0; i < logV; i++) ans += (ll) res[i] * (1 << i); cout << ans; } int main(){ //freopen(taskname".inp", "r", stdin); //freopen(taskname".out", "w", stdout); readInput(); solve(); return 0; }

Compilation message (stderr)

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