#include<bits/stdc++.h>
using namespace std;
#define sqr(x) 1ll*x*(x+1)>>1ll
typedef long long ll;
int n,col[200100],sz[200100];
map<int,int>f[200100];
vector<int>v[200100],res[200100];
void dfs(int x,int fa){
	sz[x]=1;
	for(int y:v[x]){
		if(y==fa)continue;
		dfs(y,x),sz[x]+=sz[y];
		int cc=sz[y];
		if(f[y].find(col[x])!=f[y].end())cc-=f[y][col[x]];
		res[col[x]].push_back(cc);
		if(f[x].size()<f[y].size())swap(f[x],f[y]);
		for(auto i:f[y])f[x][i.first]+=i.second; 
	}
	f[x][col[x]]=sz[x];
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&col[i]);
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),v[x].push_back(y),v[y].push_back(x);
	dfs(1,0);
	for(int i=1;i<=n;i++)res[i].push_back(n-f[1][i]);
	for(int i=1;i<=n;i++){
		ll ans=sqr(n);
		for(auto j:res[i])ans-=sqr(j);
		printf("%lld\n",ans);
	}
	return 0;
}