# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
335779 | monus1042 | Deblo (COCI18_deblo) | C++17 | 131 ms | 65536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// NK
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()
#define Bolivia_is_nice ios::sync_with_stdio(false), cin.tie(nullptr)
//typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ord_set;
const int MAXS = 1e5+2;
const int LOG = 29;
vector<ll> ve(MAXS);
vector<int> g[MAXS];
ll dp[MAXS][LOG][2];
ll ans;
void dfs(int u, int p){
for (int i=0; i<g[u].size(); i++){
int v = g[u][i];
if (v!=p){
dfs(v, u);
for (int j=0; j<LOG; j++){
int ison = ((int)ve[u] >> j) & 1;
ll temp = dp[u][j][0] * dp[v][j][1] + dp[u][j][1] * dp[v][j][0];
ans += temp * (1 << j);
dp[u][j][1] += dp[v][j][ison^1];
ans += dp[v][j][ison^1] * (1<<j);
dp[u][j][0] += dp[v][j][ison];
}
}
}
for (int i=0; i<LOG; i++){
int ison = ((int)ve[u] >> i) & 1;
dp[u][i][ison]++;
}
}
void solve(){
int n; cin >> n;
for (int i=1; i<=n; i++){
cin >> ve[i];
ans += ve[i];
}
for (int i=1; i<n; i++){
int u,v; cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1,-1);
cout << ans << '\n';
}
int main(){
/*Bolivia_is_nice;
int t = 1; cin>>t;
while(t--)
solve();*/
Bolivia_is_nice;
solve();
return 0;
}
/*
~/.emacs
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |