Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
struct graph
{
    int head[maxn],nxt[maxn<<1],to[maxn<<1],w[maxn<<1],sz;
    void init(){memset(head,-1,sizeof(head));}
    graph(){init();}
    void push(int a,int b,int c){nxt[sz]=head[a],to[sz]=b,w[sz]=c,head[a]=sz++;}
    int& operator[](const int a){return to[a];}
}g;
int a[maxn],sum[maxn],size[maxn];
ll ans[maxn];
ll get(int x)
{
    return 1ll*x*(x+1)/2;
}
void dfs(int now,int pre)
{
    size[now]=1;
    int tmp = sum[a[now]];
    for(int i = g.head[now];~i;i = g.nxt[i]){
        if(g[i]==pre)continue;
        sum[a[now]]=0;
        dfs(g[i],now);
        size[now]+=size[g[i]];
        ans[a[now]]-=get(size[g[i]]-sum[a[now]]);
    }
    sum[a[now]]=tmp+size[now];
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= n;++i)scanf("%d",&a[i]);
    for(int i = 1,a,b;i < n;++i){
        scanf("%d%d",&a,&b);
        g.push(a,b,0);
        g.push(b,a,0);
    }
    for(int i = 1;i <= n;++i)ans[i]=get(n);
    dfs(1,0);
    for(int i = 1;i <= n;++i){
        ans[i]-=get(n-sum[i]);
    }
    for(int i = 1;i <= n;++i)printf("%lld\n",ans[i]);
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:23:5: error: reference to 'size' is ambiguous
   23 |     size[now]=1;
      |     ^~~~
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:15:23: note:                 'int size [200005]'
   15 | int a[maxn],sum[maxn],size[maxn];
      |                       ^~~~
a.cc:29:9: error: reference to 'size' is ambiguous
   29 |         size[now]+=size[g[i]];
      |         ^~~~
/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:15:23: note:                 'int size [200005]'
   15 | int a[maxn],sum[maxn],size[maxn];
      |                       ^~~~
a.cc:29:20: error: reference to 'size' is ambiguous
   29 |         size[now]+=size[g[i]];
      |                    ^~~~
/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:15:23: note:                 'int size [200005]'
   15 | int a[maxn],sum[maxn],size[maxn];
      |                       ^~~~
a.cc:30:26: error: reference to 'size' is ambiguous
   30 |         ans[a[now]]-=get(size[g[i]]-sum[a[now]]);
      |                          ^~~~
/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:15:23: note:                 'int size [200005]'
   15 | int a[maxn],sum[maxn],size[maxn];
      |                       ^~~~
a.cc:32:21: error: reference to 'size' is ambiguous
   32 |     sum[a[now]]=tmp+size[now];
      |                     ^~~~
/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:15:23: note:                 'int size [200005]'
   15 | int a[maxn],sum[maxn],size[maxn];
      |                       ^~~~