Language: C++

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;

#define MAX 200005

vector<int> adjacents[MAX];
int color[MAX];
int size[MAX] = {0};

// acumColorTrees[i] : 色iのノードを根にもつ部分木のサイズ総計
// ただし部分木に部分木が含まれる場合は大きいほうのみ計上
int acumColorTrees[MAX] = {0};

// 色iを含まない部分木の各々についてそのサイズを保存しておく
stack<int> isolateTrees[MAX];

void dfs(int node, int parent)
{
    int col = color[node];
    int bef1 = acumColorTrees[col];

    for (int adj : adjacents[node]) {
        if (adj == parent) continue;
        int bef2 = acumColorTrees[col];
        dfs(adj, node);
        int cut = acumColorTrees[col] - bef2;
        isolateTrees[col].push(size[adj] - cut);
        size[node] += size[adj];
    }
    size[node]++;
    acumColorTrees[col] = bef1 + size[node];
}


int main(int, char**)
{
    int n;
    cin >> n;

    int tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        color[i] = tmp-1;
    }
    int a, b;
    for (int i = 0; i < n-1; i++) {
        cin >> a >> b;
        a--; b--;
        adjacents[a].push_back(b);
        adjacents[b].push_back(a);
    }

    dfs(0, -1);
    for (int i = 0; i < n; i++) {
        isolateTrees[i].push(n - acumColorTrees[i]);
    }
    for (int i = 0; i < n; i++) {
        ll all = n * (n+1) / 2;
        ll notColUse = 0;
        ll tree;
        while (!isolateTrees[i].empty()) {
            tree = isolateTrees[i].top();
            isolateTrees[i].pop();
            notColUse += tree * (tree+1) / 2;
        }
        cout << all - notColUse << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:31:32: error: reference to 'size' is ambiguous
   31 |         isolateTrees[col].push(size[adj] - cut);
      |                                ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:12:5: note:                 'int size [200005]'
   12 | int size[MAX] = {0};
      |     ^~~~
a.cc:32:9: error: reference to 'size' is ambiguous
   32 |         size[node] += size[adj];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:12:5: note:                 'int size [200005]'
   12 | int size[MAX] = {0};
      |     ^~~~
a.cc:32:23: error: reference to 'size' is ambiguous
   32 |         size[node] += size[adj];
      |                       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:12:5: note:                 'int size [200005]'
   12 | int size[MAX] = {0};
      |     ^~~~
a.cc:34:5: error: reference to 'size' is ambiguous
   34 |     size[node]++;
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:12:5: note:                 'int size [200005]'
   12 | int size[MAX] = {0};
      |     ^~~~
a.cc:35:34: error: reference to 'size' is ambiguous
   35 |     acumColorTrees[col] = bef1 + size[node];
      |                                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:12:5: note:                 'int size [200005]'
   12 | int size[MAX] = {0};
      |     ^~~~