제출 #890294

#제출 시각아이디문제언어결과실행 시간메모리
890294pccDeblo (COCI18_deblo)C++14
90 / 90
97 ms18440 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> #define int ll const int mxn = 1e5+10; vector<int> tree[mxn]; int val[mxn],dp[mxn][2],arr[mxn]; int n; ll ans = 0; void dfs(int now,int par,int bit){ dp[now][0] = dp[now][1] = 0; dp[now][(arr[now]&(1<<bit)?1:0)] = 1; val[now] = (arr[now]&(1<<bit)?1:0); for(auto nxt:tree[now]){ if(nxt == par)continue; dfs(nxt,now,bit); ans += 1ll*dp[now][1]*dp[nxt][0]*(1<<bit); ans += 1ll*dp[now][0]*dp[nxt][1]*(1<<bit); dp[now][val[now]] += dp[nxt][0]; dp[now][val[now]^1] += dp[nxt][1]; } return; } main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n; for(int i = 1;i<=n;i++)cin>>arr[i]; for(int i = 1;i<n;i++){ int a,b; cin>>a>>b; tree[a].push_back(b); tree[b].push_back(a); } for(int i = 0;i<22;i++){ dfs(1,1,i); } for(int i = 1;i<=n;i++)ans += arr[i]; cout<<ans; }

컴파일 시 표준 에러 (stderr) 메시지

deblo.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...