Submission #707432

# Submission time Handle Problem Language Result Execution time Memory
707432 2023-03-09T02:14:29 Z nguyentunglam Deblo (COCI18_deblo) C++17
90 / 90
139 ms 35368 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 10;
int a[N], f[2][26][N];
vector<int> adj[N];
long long res;
void dfs(int u, int par, int h) {
    for(int bit = 0; bit <= 22; bit++) f[(h >> bit) & 1][bit][u]++;
    res += a[u];
    for(int v : adj[u]) if (v != par) {
        dfs(v, u, h ^ a[v]);
        for(int bit = 0; bit <= 22; bit++) for(int j = 0; j < 2; j++) for(int k = 0; k < 2; k++) {
            bool x = (a[u] >> bit) & 1;
            if (x ^ j ^ k) res += (1LL << bit) * f[j][bit][u] * f[k][bit][v];
        }
        for(int bit = 0; bit <= 22; bit++) for(int j = 0; j < 2; j++) f[j][bit][u] += f[j][bit][v];
    }
}
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int n; cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, 0, a[1]);
    cout << res;
}

Compilation message

deblo.cpp: In function 'int main()':
deblo.cpp:27:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
deblo.cpp:28:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
deblo.cpp:31:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
deblo.cpp:32:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2900 KB Output is correct
2 Correct 2 ms 2900 KB Output is correct
3 Correct 2 ms 2900 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 70 ms 35368 KB Output is correct
7 Correct 69 ms 35356 KB Output is correct
8 Correct 66 ms 27724 KB Output is correct
9 Correct 69 ms 27004 KB Output is correct
10 Correct 139 ms 26224 KB Output is correct