Language: C++

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN=200005;
int n,len;
int color[MAXN],head[MAXN],size[MAXN],num[MAXN];
ll ans[MAXN];

struct node{
	int to,next;
} e[MAXN * 2];

void add(int u,int v){
	e[++len].to = v;
	e[len].next = head[u];
	head[u] = len;
}

ll f(ll n){
	return 1ll * n * (n + 1) / 2;
}

void dfs(int u,int fa){	
	int c = color[u];
	int lst,d;
	size[u] = 1;
	ll tmp = num[c];
	for(int i = head[u];i != -1;i = e[i].next){
		int v = e[i].to;
		if(v == fa)
			continue;
		lst = num[c];
		dfs(v,u);
		d = num[c] - lst;
		ans[c] -= f(size[v] - d);
		size[u] += size[v];
	}
	num[c] = tmp + size[u];
}

int main(){
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&color[i]);
		ans[i] = f(n);
	}
	for(int i = 1;i < n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs(1,0);
	for(int i = 1;i <= n;i++){
		ans[i] -= f(n - num[i]);
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:33:9: error: reference to 'size' is ambiguous
   33 |         size[u] = 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:13:28: note:                 'int size [200005]'
   13 | int color[MAXN],head[MAXN],size[MAXN],num[MAXN];
      |                            ^~~~
a.cc:42:29: error: reference to 'size' is ambiguous
   42 |                 ans[c] -= f(size[v] - d);
      |                             ^~~~
/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:13:28: note:                 'int size [200005]'
   13 | int color[MAXN],head[MAXN],size[MAXN],num[MAXN];
      |                            ^~~~
a.cc:43:17: error: reference to 'size' is ambiguous
   43 |                 size[u] += size[v];
      |                 ^~~~
/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:13:28: note:                 'int size [200005]'
   13 | int color[MAXN],head[MAXN],size[MAXN],num[MAXN];
      |                            ^~~~
a.cc:43:28: error: reference to 'size' is ambiguous
   43 |                 size[u] += size[v];
      |                            ^~~~
/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:13:28: note:                 'int size [200005]'
   13 | int color[MAXN],head[MAXN],size[MAXN],num[MAXN];
      |                            ^~~~
a.cc:45:24: error: reference to 'size' is ambiguous
   45 |         num[c] = tmp + size[u];
      |                        ^~~~
/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:13:28: note:                 'int size [200005]'
   13 | int color[MAXN],head[MAXN],size[MAXN],num[MAXN];
      |                            ^~~~