Submission #384901

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

Compilation message

deblo.cpp: In function 'int main()':
deblo.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     int n; scanf ("%d", &n);
      |            ~~~~~~^~~~~~~~~~
deblo.cpp:45:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     for (int i = 1; i <= n; ++i) scanf ("%d", c + i);
      |                                  ~~~~~~^~~~~~~~~~~~~
deblo.cpp:47:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         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 4 ms 2924 KB Output is correct
5 Correct 4 ms 3072 KB Output is correct
6 Incorrect 101 ms 35308 KB Output isn't correct
7 Incorrect 91 ms 35200 KB Output isn't correct
8 Incorrect 116 ms 28780 KB Output isn't correct
9 Incorrect 121 ms 28140 KB Output isn't correct
10 Incorrect 143 ms 27372 KB Output isn't correct