#include <bits/stdc++.h>
#define LL long long
#define PLL pair<LL, LL>
#define x first
#define y second 
using namespace std;
//const LL INF = (LL) 1e9 + 5;
//const LL MOD = (LL) 1e9 + 7;
const int MAXN = 200005;

int n, timer, col[MAXN], tin[MAXN], tout[MAXN];
LL ans[MAXN], sz[MAXN];
set<PLL> ord[MAXN];
vector<int> G[MAXN];

LL way(LL k) {
	return k * (k - 1) / 2 + k;
}

void dfs(int v, int p) {
	sz[v] = 1;
	tin[v] = ++timer;
	for (int to : G[v]) {
		if (to == p) continue;
		dfs(to, v);
		sz[v] += sz[to];
		
//		if (col[to] != col[v]) {
			LL tot = sz[to];
			auto it = ord[col[v]].lower_bound(PLL(tin[to], -1));
			while (it != ord[col[v]].end() && it->x <= tout[to]) {
				tot -= it->y;
				it = ord[col[v]].erase(it);
			}
			ans[col[v]] -= way(tot);
//		}
	}
	
	tout[v] = timer;
	ord[col[v]].insert(PLL(tin[v], sz[v]));
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> col[i];
		ans[i] = way(n);
	}
	for (int i = 1; i <= n - 1; i++) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	dfs(1, 1);
	for (int i = 1; i <= n; i++) {
		if (i != col[1]) {
			LL tot = n;
			for (auto p : ord[i]) {
				tot -= p.y;
			}
			ans[i] -= way(tot);
		}
	}
	
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << '\n';
	}
	
	return 0;
}