| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 305500 | phathnv | Deblo (COCI18_deblo) | C++11 | 161 ms | 33120 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "Deblo"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 1e5 + 1;
const int logV = 22;
int n, a[N];
vector <int> adj[N];
int cnt[N][logV][2];
ll res[logV];
void readInput(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for(int i = 1; i < n; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}
void dfs(int u, int p){
    for(int i = 0; i < logV; i++){
        int bit = (a[u] >> i) & 1;
        cnt[u][i][bit]++;
        if (bit)
            res[i]++;
    }
    for(int v : adj[u])
        if (v != p){
            dfs(v, u);
            for(int i = 0; i < logV; i++){
                res[i] += (ll) cnt[u][i][1] * cnt[v][i][0];
                res[i] += (ll) cnt[u][i][0] * cnt[v][i][1];
                int bit = (a[u] >> i) & 1;
                cnt[u][i][0] += cnt[v][i][0 ^ bit];
                cnt[u][i][1] += cnt[v][i][1 ^ bit];
            }
        }
}
void solve(){
    dfs(1, -1);
    ll ans = 0;
    for(int i = 0; i < logV; i++)
        ans += (ll) res[i] * (1 << i);
    cout << ans;
}
int main(){
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);
    readInput();
    solve();
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
