Submission #778646

#TimeUsernameProblemLanguageResultExecution timeMemory
778646vjudge1Deblo (COCI18_deblo)C++17
45 / 90
1065 ms11524 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #include<iostream> #include <vector> #include <bitset> 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 int arr[N]; vector<int> adj[N]; bitset<100001>isaret; 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); ll int cev=0; for(int i=yol.size()-1;i>-1;i--){ cev+=dfs(yol[i],-1,0); isaret[yol[i]]=1; } cout<<cev<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...