#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e5 + 10;
int n, c[N], cnt[N], siz[N];
	inline LL count(int n) {
		// C(n,2) + n
		return 1LL*n*(n+1)/2;
	}
LL ans[N];
vector<int>G[N];
	void dfs(int v, int fa) {
		int tmp = cnt[c[v]];
		siz[v] = 1;
		for(int u:G[v]) {
			if(u==fa) continue;
			cnt[c[v]] = 0;
			dfs(u, v);
			siz[v] += siz[u];
			ans[c[v]]+=count(siz[u]-cnt[c[v]]);
		}
		cnt[c[v]] = tmp + siz[v];
	}
	
	#define ADD(a, b) 	\
		do {			\
			G[a].push_back(b);	\
			G[b].push_back(a);	\
		}while(0);		
		
	inline void add(int a, int b) {
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
int main() {
	//scanf("%d", &n);
	std::ios::sync_with_stdio(false);
	cin>>n;
	for (int i = 1; i <= n; i++)
		//scanf("%d", &c[i]);
		cin>>c[i];
	for (int i = 1; i < n; i++) {
		int u, v;
		//scanf("%d%d", &u, &v);
		cin>>u>>v;
		//G[u].push_back(v);
		//G[v].push_back(u);
		add(u, v);
		//ADD(u, v); ADD(v, u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		cout<< count(n) - ans[i] - count(n - cnt[i])<<endl;
	}
	return 0;
}
