#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,c[200100],sz[200100],uu,vv;
vector<int> ga[200100];
long long sum[200100],res[200100];
long long Magic(long long x){
	return x*(x+1LL)/2LL;
}
void dfs(int u,int p){
	int co=c[u];
	long long pre=sum[co];
	sz[u]=1;
	for(int v:ga[u]){
		if(v==p)
			continue;
		long long lst=sum[co];
		dfs(v,u);
		long long delta=sum[co]-lst;
		sz[u]+=sz[v];
		res[co]-=Magic(sz[v]-delta);
	}
	sum[co]=pre+sz[u];
}
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		res[i]=Magic(n); 
	}
	for(int i=1;i<n;i++){
		cin>>uu>>vv;
		ga[uu].push_back(vv);
		ga[vv].push_back(uu);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++){
		res[i]-=Magic(n-sum[i]);
		cout<<res[i]<<endl;
	}
	return 0;
}
