# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
527883 | 2022-02-18T15:47:02 Z | aris12345678 | Deblo (COCI18_deblo) | C++14 | 50 ms | 8436 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2636 KB | Output is correct |
2 | Correct | 2 ms | 2636 KB | Output is correct |
3 | Correct | 2 ms | 2636 KB | Output is correct |
4 | Correct | 14 ms | 2636 KB | Output is correct |
5 | Correct | 16 ms | 2636 KB | Output is correct |
6 | Correct | 49 ms | 8412 KB | Output is correct |
7 | Correct | 47 ms | 8416 KB | Output is correct |
8 | Incorrect | 49 ms | 8388 KB | Output isn't correct |
9 | Incorrect | 50 ms | 8436 KB | Output isn't correct |
10 | Incorrect | 48 ms | 8340 KB | Output isn't correct |