#include<bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N=2e5+5;

i64 ans[N];
int x[N];
int s[N];
int c[N];
vector<int>e[N];

void dfs(int v,int p){
	int i,l=x[c[v]];s[v]=1;
	for(i=0;i<e[v].size();i++)
		if(e[v][i]!=p)
			x[c[v]]=0,dfs(e[v][i],v),s[v]+=s[e[v][i]],
			ans[c[v]]-=1ll*(s[e[v][i]]-x[c[v]])*(s[e[v][i]]-x[c[v]]+1)/2;
	x[c[v]]=l+s[v];
}

int main()
{
	int n,i,u,v;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&c[i]);
		ans[c[i]]=1ll*n*(n+1)/2;
	}
	for(i=1;i<n;i++)
		scanf("%d%d",&u,&v),
		e[u].push_back(v),
		e[v].push_back(u);
	dfs(1,0);
	for(i=1;i<=n;i++)
		if(ans[i])ans[i]-=1ll*(n-x[i])*(n-x[i]+1)/2;
	for(i=1;i<=n;i++)
		printf("%lld\n",ans[i]);
	return 0;
}