Submission #384902

# Submission time Handle Problem Language Result Execution time Memory
384902 2021-04-02T15:00:59 Z AdiZer0 Deblo (COCI18_deblo) C++17
90 / 90
143 ms 58220 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;

ll c[N], ans[27], dp[N][27][2];
vector<ll> 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() {
    ll n; scanf ("%lld", &n);
    for (int i = 1; i <= n; ++i) scanf ("%lld", c + i);
    for (int i = 1; i < n; ++i) { 
        ll u, v; scanf ("%lld %lld", &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:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     ll n; scanf ("%lld", &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 ("%lld", c + i);
      |                                  ~~~~~~^~~~~~~~~~~~~~~
deblo.cpp:47:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         ll u, v; scanf ("%lld %lld", &u, &v);
      |                  ~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 3 ms 2932 KB Output is correct
4 Correct 4 ms 3180 KB Output is correct
5 Correct 4 ms 3180 KB Output is correct
6 Correct 115 ms 58220 KB Output is correct
7 Correct 117 ms 58220 KB Output is correct
8 Correct 105 ms 51052 KB Output is correct
9 Correct 105 ms 50156 KB Output is correct
10 Correct 143 ms 49516 KB Output is correct