Submission #98321

# Submission time Handle Problem Language Result Execution time Memory
98321 2019-02-22T09:12:39 Z mayhoubsaleh Maja (COCI18_maja) C++14
0 / 110
19 ms 5260 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;
ll n,a[100005],ans,pat[1000005][25],cnt[100005];
vector<ll>v[100005];

ll qr(ll cnt1,ll x[],ll cnt2,ll y[]){
    ll ret=0;
    for(ll i=0;i<25;i++){
        ll b=x[i]*(cnt2-y[i])+y[i]*(cnt1-x[i]);
        ret+=b*(1<<i);
    }
    return ret;
}

void xorr(ll x,ll cnt,ll a[]){
    for(ll i=0;i<25;i++){
        if(((1<<i)&x)==0)continue;
        a[i]=cnt-a[i];
    }
}

void add(ll x[],ll y[]){
    for(ll i=0;i<25;i++){
        x[i]+=y[i];
    }
}
void dfs(ll nod,ll par){
    ans+=a[nod];
    cnt[nod]=1;
    for(ll i=0;i<25;i++){
        pat[nod][i]=(bool)(a[nod]&(1<<i))!=0;
    }
    for(auto ch:v[nod]){
        if(ch==par)continue;
        dfs(ch,nod);
        ans+=qr(cnt[nod],pat[nod],cnt[ch],pat[ch]);
        xorr(a[nod],cnt[ch],pat[ch]);
        add(pat[nod],pat[ch]);
        cnt[nod]+=cnt[ch];
    }
}
int main(){
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    for(ll i=0;i<n-1;i++){
        ll a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    dfs(1,0);
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 5240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 5260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 5220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -