| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 750486 | Trunkty | Deblo (COCI18_deblo) | C++14 | 276 ms | 19420 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n,ans;
int arr[100005];
vector<int> roads[100005];
int dp[100005][2];
void dfs(int x, int p, int j){
    dp[x][0] = 0;
    dp[x][1] = 0;
    for(int i:roads[x]){
        if(i!=p){
            dfs(i,x,j);
            dp[x][0] += dp[i][0];
            dp[x][1] += dp[i][1];
        }
    }
    int tot=0;
    if(arr[x]&(1LL<<j)){
        tot += (1LL<<j)*(dp[x][0]*dp[x][0]+dp[x][1]*dp[x][1]);
        for(int i:roads[x]){
            if(i!=p){
                tot -= (1LL<<j)*(dp[i][0]*dp[i][0]+dp[i][1]*dp[i][1]);
            }
        }
        tot /= 2LL;
    }
    else{
        tot += (1LL<<j)*(dp[x][0]*dp[x][1]);
        for(int i:roads[x]){
            if(i!=p){
                tot -= (1LL<<j)*(dp[i][0]*dp[i][1]);
            }
        }
    }
    ans += tot;
    if(arr[x]&(1LL<<j)){
        ans += (1LL<<j)*(dp[x][0]+1LL);
        swap(dp[x][0],dp[x][1]);
        dp[x][1]++;
    }
    else{
        ans += (1LL<<j)*dp[x][1];
        dp[x][0]++;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> arr[i];
    }
    for(int i=1;i<=n-1;i++){
        int a,b;
        cin >> a >> b;
        roads[a].push_back(b);
        roads[b].push_back(a);
    }
    for(int j=0;j<=25;j++){
        dfs(1,-1,j);
    }
    cout << ans << "\n";
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
