Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
vector<ll>tree[maxn];
ll color[maxn],size[maxn],colson[maxn],ans[maxn];
ll f(ll n){return n*(n+1)/2;}
void dfs(ll u,ll father){
	ll last=colson[color[u]];
	ll v;
	for(ll i=0;i<tree[u].size();i++){
		v=tree[u][i];
		if(v==father)continue;
		dfs(v,u);
		size[u]+=size[v];
		ans[color[u]]-=f(size[v]-colson[color[u]]);
	}
	colson[color[u]]=last+size[u];
}
int main(){
	ll n,u,v;
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++){
		scanf("%lld",&color[i]);
		ans[i]=f(n);
		size[i]=1;
	}
	for(ll i=1;i<=n-1;i++){
		scanf("%lld%lld",&u,&v);
		tree[u].push_back(v);
		tree[v].push_back(u);
	}
	dfs(1,0);
	for(ll i=1;i<=n;i++) printf("%lld\n",ans[i]-f(n-colson[i]));
}

Compiler output:
a.cc: In function 'void dfs(ll, ll)':
a.cc:15:17: error: reference to 'size' is ambiguous
   15 |                 size[u]+=size[v];
      |                 ^~~~
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:6:16: note:                 'll size [200005]'
    6 | ll color[maxn],size[maxn],colson[maxn],ans[maxn];
      |                ^~~~
a.cc:15:26: error: reference to 'size' is ambiguous
   15 |                 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:6:16: note:                 'll size [200005]'
    6 | ll color[maxn],size[maxn],colson[maxn],ans[maxn];
      |                ^~~~
a.cc:16:34: error: reference to 'size' is ambiguous
   16 |                 ans[color[u]]-=f(size[v]-colson[color[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:6:16: note:                 'll size [200005]'
    6 | ll color[maxn],size[maxn],colson[maxn],ans[maxn];
      |                ^~~~
a.cc:18:31: error: reference to 'size' is ambiguous
   18 |         colson[color[u]]=last+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:6:16: note:                 'll size [200005]'
    6 | ll color[maxn],size[maxn],colson[maxn],ans[maxn];
      |                ^~~~
a.cc: In function 'int main()':
a.cc:26:17: error: reference to 'size' is ambiguous
   26 |                 size[i]=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:6:16: note:                 'll size [200005]'
    6 | ll color[maxn],size[maxn],colson[maxn],ans[maxn];
      |                ^~~~