# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384888 | 2021-04-02T14:50:28 Z | AdiZer0 | Deblo (COCI18_deblo) | C++17 | 118 ms | 36716 KB |
#include <bits/stdc++.h> #define pb push_back #define whole(x) x.begin(), x.end() #define sz(x) (int)x.size() using namespace std; typedef long long ll; typedef long double ld; const int N = (int)1e5 + 7; const int INF = (int)1e9 + 7; const ll linf = (ll)1e18 + 1; int c[N], ans[27], dp[N][27][2]; vector<int> g[N]; void dfs(int v, int par = -1) { for (int bit = 0; bit < 26; ++bit) { if ((c[v] >> bit) & 1) ++ans[bit]; dp[v][bit][((c[v] >> bit) & 1)] = 1; } for (int to : g[v]) { if (par == to) continue; dfs(to, v); for (int bit = 0; bit < 26; ++bit) { ans[bit] += (dp[v][bit][1] * 1ll * dp[to][bit][0]); ans[bit] += (dp[v][bit][0] * 1ll * dp[to][bit][1]); if ((c[v] >> bit) & 1) { dp[v][bit][1] += dp[to][bit][0]; dp[v][bit][0] += dp[to][bit][1]; } else { dp[v][bit][1] += dp[to][bit][1]; dp[v][bit][0] += dp[to][bit][0]; } } } } int main() { int n; scanf ("%d", &n); for (int i = 1; i <= n; ++i) scanf ("%d", c + i); for (int i = 1; i < n; ++i) { int u, v; scanf ("%d %d", &u, &v); g[u].pb(v), g[v].pb(u); } dfs(1); ll res = 0; for (int i = 0; i < 26; ++i) res += (ans[i] * 1ll * (1 << i)); printf ("%lld\n", res); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2668 KB | Output is correct |
2 | Correct | 3 ms | 2668 KB | Output is correct |
3 | Correct | 3 ms | 2668 KB | Output is correct |
4 | Correct | 4 ms | 2924 KB | Output is correct |
5 | Correct | 3 ms | 2924 KB | Output is correct |
6 | Incorrect | 94 ms | 36716 KB | Output isn't correct |
7 | Incorrect | 93 ms | 36716 KB | Output isn't correct |
8 | Incorrect | 102 ms | 29056 KB | Output isn't correct |
9 | Incorrect | 95 ms | 28268 KB | Output isn't correct |
10 | Incorrect | 118 ms | 27372 KB | Output isn't correct |