#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (ll)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define crep(i,x,n) for(ll i=x;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _34raRxL ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
void prll(){
cout<<"\n";
}
template<class te,class ...ti>
void prll(const te&v, const ti&...nv) {
cout<<v;
if(sizeof...(nv)){
cout<<" ";
prll(nv...);
}
}
using tpii=pair<ll,pair<ll,ll>>;
using pii=pair<ll,ll>;
using vi=vector<ll>;
using vll=vector<long long>;
void slv(){
ll n;
cin>>n;
vi a(n);
rep(i,n){
cin>>a[i];
}
vec(vi) adj(n);
rep(i,n-1){
ll u,v;
cin>>u>>v;
u--,v--;
adj[u].pb(v);
adj[v].pb(u);
}
vec(vec(vi)) cnt(n,vec(vi)(26,vi(3)));
vi pxor(n,-1);
ll ans=0;
auto dfs=[&](auto self,ll v,ll par)->void{
if(par!=-1){
pxor[v]=pxor[par];
}
// ll x=a[v];
// ans+=x;
// pxor[v]^=x;
for(auto u : adj[v]){
if(u!=par){
self(self,u,v);
}
}
// rep(j,25){
// for(auto u : adj[v]){
// if(u==par){
// continue;
// }
// // if(x&(1ll<<j)){
// // // [0,0],[1,1]
// // ans+=(1ll<<j)*cnt[u][j][0]*cnt[v][j][0];
// // ans+=(1ll<<j)*cnt[u][j][1]*cnt[v][j][1];
// // }else{
// // // [0,1],[1,0]
// // ans+=(1ll<<j)*cnt[u][j][0]*cnt[v][j][1];
// // ans+=(1ll<<j)*cnt[u][j][1]*cnt[v][j][0];
// // }
// // if((pxor[v]^x)&(1ll<<j)){
// // // if(v==0 and u==1){
// // // prll(pxor[x],"\n");
// // // }
// // ans+=(1ll<<j)*cnt[u][j][0];
// // }else{
// // ans+=(1ll<<j)*cnt[u][j][1];
// // }
// // cnt[v][j][0]+=cnt[u][j][0];
// // cnt[v][j][1]+=cnt[u][j][1];
// }
// // cnt[v][j][bool(pxor[v]&(1ll<<j))]++;
// }
};
dfs(dfs,0,-1);
prll(ans,"\n");
}
int main(){
_34raRxL;
ll t=1;
// cin>>t;
slv();
//
return 0;
}
Compilation message
deblo.cpp: In function 'int main()':
deblo.cpp:97:5: warning: unused variable 't' [-Wunused-variable]
97 | ll t=1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
1740 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
1740 KB |
Output isn't correct |
6 |
Runtime error |
81 ms |
65540 KB |
Execution killed with signal 9 |
7 |
Runtime error |
79 ms |
65540 KB |
Execution killed with signal 9 |
8 |
Runtime error |
81 ms |
65540 KB |
Execution killed with signal 9 |
9 |
Runtime error |
81 ms |
65540 KB |
Execution killed with signal 9 |
10 |
Runtime error |
81 ms |
65540 KB |
Execution killed with signal 9 |