제출 #240936

#제출 시각아이디문제언어결과실행 시간메모리
240936DavidDamianDeblo (COCI18_deblo)C++11
45 / 90
1096 ms14712 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ///Subtask 2 ///DFS from all nodes int n; ll A[100005]; ll total=0; vector<int> adjList[100005]; ll dfs(int u,int e,ll Xor) { ll sum=Xor; for(int v: adjList[u]){ if(v==e) continue; sum+=dfs(v,u,Xor^A[v]); } return sum; } int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>A[i]; total+=A[i]; } for(int i=1;i<=n-1;i++){ int a,b; cin>>a>>b; adjList[a].push_back(b); adjList[b].push_back(a); } for(int i=1;i<=n;i++){ total+=dfs(i,0,A[i]); } total/=2; cout<<total<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...