#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define ll long long
#define pb push_back
#define N 100001
#define f first
#define s second
ll int cev=0;
int arr[N];
vector<int> adj[N];
int yukar[N],asa[N], isaret[N];
ll int dfs(int x,int once,int prevgel){
ll int topla=0;
if(isaret[x]==0)topla=prevgel^arr[x];
for(auto u:adj[x]){
if(u==once) continue;
topla+=dfs(u,x,prevgel^arr[x]);
}
return topla;
}
vector<int> yol;
void uff(int x,int once){
for(auto u:adj[x]){
if(u!=once)uff(u,x);
}
yol.pb(x);
}
int main(){
lalala;
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>arr[i];
for(int i=0;i<n-1;i++){
int a,b;cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
uff(1,0);
reverse(yol.begin(),yol.end());
ll int cev=0;
for(auto u:yol){
cev+=dfs(u,-1,0);
//cout<<cev<<" "<<u<<endl;
isaret[u]=1;
}
cout<<cev<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
7 ms |
2644 KB |
Output is correct |
5 |
Correct |
8 ms |
2736 KB |
Output is correct |
6 |
Execution timed out |
1089 ms |
16424 KB |
Time limit exceeded |
7 |
Execution timed out |
1072 ms |
16360 KB |
Time limit exceeded |
8 |
Execution timed out |
1085 ms |
8156 KB |
Time limit exceeded |
9 |
Execution timed out |
1079 ms |
7476 KB |
Time limit exceeded |
10 |
Execution timed out |
1082 ms |
7152 KB |
Time limit exceeded |