#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int n;
int c[N], cnt[N], siz[N];
ll ans[N];
vector<int>G[N];
ll cal(int x) {
	return 1ll * x*(x - 1) / 2 + x;
}
void dfs(int u, int _fa) {
	siz[u] = 1;
	int tmp = cnt[c[u]];
	for (int v : G[u]) {
		if (v == _fa)continue;
		cnt[c[u]] = 0;
		dfs(v, u);
		siz[u] += siz[v];
		ans[c[u]] += cal(siz[v] - cnt[c[u]]);
	}
	cnt[c[u]] = tmp + siz[u];
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &c[i]);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", cal(n) - ans[i] - cal(n - cnt[i]));
	}
	return 0;
}