| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 522427 | KoD | Deblo (COCI18_deblo) | C++17 | 144 ms | 12616 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::tuple;
using std::pair;
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    std::cin >> N;
    vector<int> A(N);
    for (auto& x : A) {
        std::cin >> x;
    }    
    vector<vector<int>> graph(N);
    for (int i = 1; i < N; ++i) {
        int a, b;
        std::cin >> a >> b;
        a -= 1, b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> parent(N), order;
    order.reserve(N);
    auto dfs = [&](auto&& self, const int u) -> void {
        order.push_back(u);
        for (const int v : graph[u]) {
            if (v != parent[u]) {
                parent[v] = u;
                self(self, v);
            }
        }
    };
    parent[0] = -1;
    dfs(dfs, 0);
    vector<int> accum = A;
    for (int i = 1; i < N; ++i) {
        accum[order[i]] ^= accum[parent[order[i]]];
    }
    long long ans = std::accumulate(A.begin(), A.end(), 0ll);
    for (int d = 0; d < 22; ++d) {
        long long cnt = 0;
        vector<array<int, 2>> count(N);
        for (int i = N - 1; i >= 0; --i) {
            const int u = order[i];
            const int a = A[u] >> d & 1, ac = accum[u] >> d & 1;
            for (const int v : graph[u]) {
                if (v != parent[u]) {
                    cnt += count[v][(a ^ ac ^ 1)];
                    for (int k = 0; k < 2; ++k) {
                        cnt += (long long)count[v][k] * count[u][a ^ k ^ 1];
                    }
                    for (int k = 0; k < 2; ++k) {
                        count[u][k] += count[v][k];
                    }
                }
            }
            count[u][ac] += 1;
        }
        ans += cnt << d;
    }
    std::cout << ans << '\n';
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
