Submission #384885

# Submission time Handle Problem Language Result Execution time Memory
384885 2021-04-02T14:45:17 Z AdiZer0 Deblo (COCI18_deblo) C++17
45 / 90
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 < 25; ++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 < 25; ++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 < 25; ++i) res += (ans[i] * 1ll * (1 << i));
    printf ("%lld\n", res);
    return 0;
}

Compilation message

deblo.cpp: In function 'int main()':
deblo.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |     int n; scanf ("%d", &n);
      |            ~~~~~~^~~~~~~~~~
deblo.cpp:43:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |     for (int i = 1; i <= n; ++i) scanf ("%d", c + i);
      |                                  ~~~~~~^~~~~~~~~~~~~
deblo.cpp:45:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |         int u, v; scanf ("%d %d", &u, &v);
      |                   ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 3 ms 2924 KB Output is correct
5 Correct 4 ms 2924 KB Output is correct
6 Incorrect 98 ms 36716 KB Output isn't correct
7 Incorrect 93 ms 36716 KB Output isn't correct
8 Incorrect 96 ms 29036 KB Output isn't correct
9 Incorrect 94 ms 28256 KB Output isn't correct
10 Incorrect 118 ms 27464 KB Output isn't correct