Submission #92152

#TimeUsernameProblemLanguageResultExecution timeMemory
92152KastandaDeblo (COCI18_deblo)C++11
90 / 90
212 ms13816 KiB
#include<bits/stdc++.h> using namespace std; const int N = 100005; int n, A[N], C[N][2]; long long tot, cnt; bool B[N]; vector < int > Adj[N]; void DFS(int v, int p) { if (B[v]) cnt ++; C[v][0] = C[v][1] = 0; C[v][B[v]] ++; for (int &u : Adj[v]) if (u != p) { DFS(u, v); cnt += 1LL * C[v][0] * C[u][1]; cnt += 1LL * C[v][1] * C[u][0]; C[v][0] += C[u][B[v]]; C[v][1] += C[u][!B[v]]; } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &A[i]); for (int i = 1, v, u; i < n; i++) scanf("%d%d", &v, &u), Adj[v].push_back(u), Adj[u].push_back(v); for (int j = 0; j <= 21; j++) { cnt = 0; for (int i = 1; i <= n; i++) B[i] = (A[i] >> j) & 1; DFS(1, 0); tot += cnt * (1LL << j); } return !printf("%lld", tot); }

Compilation message (stderr)

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