#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

const int MAXN = 2e5 + 5;

ll n, c[MAXN], A[MAXN], dp[MAXN], answer[MAXN];
vector<int> G[MAXN];

void dfs(int u, int p, int d){
	for(int i = 0; i < G[u].size(); i ++){
		int v = G[u][i];
		if(v != p){
			dfs(v, u, d);
			if(c[u] != d){
				dp[u] += dp[v];
				dp[v] = 0;
			}
		}
	}
	if(c[u] != d)
		++ dp[u];
}

int main(){
	ios_base::sync_with_stdio(NULL); cin.tie(); cout.tie();
	set<int> color;
	cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> c[i];
		++ A[c[i]];
		color.insert(c[i]);
	}
	for(int i = 0; i < n - 1; i ++){
		int u, v; cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	for(auto i : color){
		memset(dp, 0, (n + 1) * sizeof(ll));
		dfs(1, 1, i);
		vector<ll> blocks;
		ll ans = 0, add = 0;
		ans += A[i] * (A[i] + 1) / 2 + A[i] * (n - A[i]);
		for(int i = 1; i <= n; i ++){
			if(dp[i]){
				add += dp[i] * (n - dp[i] - A[i]);
			}
		}
		ans += add / 2;
		answer[i] = ans;
	}
	for(int i = 1; i <= n; i ++)
		cout << answer[i] << endl;
}
/**

*/