Submission #707750

#TimeUsernameProblemLanguageResultExecution timeMemory
707750ThMinh_Deblo (COCI18_deblo)C++14
90 / 90
91 ms35508 KiB
#include<bits/stdc++.h> #define forin(i,a,b) for(int i=a;i<=b;++i) #define ll long long #define int long long using namespace std; const int N = 1e5 + 10; int n; ll ans; ll val[N], d[N], bit[23][N], sz[N]; vector<int> adj[N]; void dfs(int u, int p = 0) { sz[u] = 1; forin(i,0,22) bit[i][u] += ((d[u] >> i) & 1); for(auto v : adj[u]) if(v != p) { d[v] ^= d[u]; dfs(v, u); forin(i,0,22) { int cost = 0; if((val[u] >> i) & 1) { cost += 1ll * bit[i][u] * bit[i][v] * (1 << i); cost += 1ll * (sz[u] - bit[i][u]) * (sz[v] - bit[i][v]) * (1 << i); } else { cost += 1ll * bit[i][u] * (sz[v] - bit[i][v]) * (1 << i); cost += 1ll * (sz[u] - bit[i][u]) * bit[i][v] * (1 << i); } ans += cost; } forin(i,0,22) bit[i][u] += bit[i][v]; sz[u] += sz[v]; } } int32_t main () { cin.tie(0)->sync_with_stdio(0); if(fopen("Task.inp","r")) { freopen("Task.inp","r",stdin); freopen("WA.out","w",stdout); } cin>>n; forin(i,1,n) { cin>>val[i]; d[i] = val[i]; } forin(i,1,n - 1) { int u, v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1); forin(i,1,n) ans += val[i]; cout<<ans; }

Compilation message (stderr)

deblo.cpp: In function 'int32_t main()':
deblo.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen("Task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
deblo.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen("WA.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...