Language: C++

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef long long LL;
struct Edge{
	int next,to;
}edge[N*2];
int c[N],c1[N],fi[N],se,size[N],size1[N],n,sizec[N];
LL ans[N];
inline void add_edge(int u,int v){edge[++se].next=fi[u],fi[u]=se,edge[se].to=v;}
inline void add(int u,int v){add_edge(u,v),add_edge(v,u);}
void dfs(int x,int fa){
	int w=(c[x]!=c[fa]?c[fa]:0),fa1=c1[w];
	c1[w]=x;size[x]=1;
	for(int i=fi[x];i;i=edge[i].next){
		int v=edge[i].to;if(v==fa)continue;
		dfs(v,x);size[x]+=size[v];
	}
	ans[w]-=1ll*(size[x]-size1[x])*(size[x]-size1[x]+1)/2;
	if(c1[c[x]])size1[c1[c[x]]]+=size[x];
	else sizec[c[x]]+=size[x];
	c1[w]=fa1;
}
int main(){
	int u,v;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",c+i);
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),add(u,v);
	dfs(1,0);
	for(int i=1;i<=n;i++)sizec[i]=n-sizec[i],ans[i]+=1ll*n*(n+1)/2-1ll*sizec[i]*(sizec[i]+1)/2,printf("%lld\n",ans[i]);
	return 0;
} 

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:14:17: error: reference to 'size' is ambiguous
   14 |         c1[w]=x;size[x]=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:8:25: note:                 'int size [200005]'
    8 | int c[N],c1[N],fi[N],se,size[N],size1[N],n,sizec[N];
      |                         ^~~~
a.cc:17:26: error: reference to 'size' is ambiguous
   17 |                 dfs(v,x);size[x]+=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:8:25: note:                 'int size [200005]'
    8 | int c[N],c1[N],fi[N],se,size[N],size1[N],n,sizec[N];
      |                         ^~~~
a.cc:17:35: error: reference to 'size' is ambiguous
   17 |                 dfs(v,x);size[x]+=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:8:25: note:                 'int size [200005]'
    8 | int c[N],c1[N],fi[N],se,size[N],size1[N],n,sizec[N];
      |                         ^~~~
a.cc:19:22: error: reference to 'size' is ambiguous
   19 |         ans[w]-=1ll*(size[x]-size1[x])*(size[x]-size1[x]+1)/2;
      |                      ^~~~
/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:8:25: note:                 'int size [200005]'
    8 | int c[N],c1[N],fi[N],se,size[N],size1[N],n,sizec[N];
      |                         ^~~~
a.cc:19:41: error: reference to 'size' is ambiguous
   19 |         ans[w]-=1ll*(size[x]-size1[x])*(size[x]-size1[x]+1)/2;
      |                                         ^~~~
/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:8:25: note:                 'int size [200005]'
    8 | int c[N],c1[N],fi[N],se,size[N],size1[N],n,sizec[N];
      |                         ^~~~
a.cc:20:38: error: reference to 'size' is ambiguous
   20 |         if(c1[c[x]])size1[c1[c[x]]]+=size[x];
      |                                      ^~~~
/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:8:25: note:                 'int size [200005]'
    8 | int c[N],c1[N],fi[N],se,size[N],size1[N],n,sizec[N];
      |                         ^~~~
a.cc:21:27: error: reference to 'size' is ambiguous
   21 |         else sizec[c[x]]+=size[x];
      |                           ^~~~
/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:8:25: note:                 'int size [200005]'
    8 | int c[N],c1[N],fi[N],se,size[N],size1[N],n,sizec[N];
      |                         ^~~~