#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 61;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {//最大フロー求める Ford-fulkerson
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));//最小カットの場合逆辺は0にする
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);


	ll n;
	cin >> n;
	Graph g(n);
	Array c(n);
	REP(i, n)cin >> c[i], c[i]--;
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		add_edge(g, a, b, 1, true, 1);
	}
	Matrix mat(n, Array(1, n));
	Array num(n, 0);

	auto dfs = [&](auto dfs,ll v, ll par)->ll {
		ll ret = 0;
		ll now = num[c[v]];
		REP(i, g[v].size()) {
			ll to = g[v][i].to;
			if (to == par)continue;
			mat[c[v]].push_back(0);
			num[c[v]] = mat[c[v]].size() - 1;
			ll tmp = dfs(dfs, to, v);
			mat[c[v]][num[c[v]]] += tmp;
			ret += tmp;

		}
		ret++;
		num[c[v]] = now;
		mat[c[v]][num[c[v]]] -= ret;
		return ret;
	};

	dfs(dfs, 0, -1);
	REP(i, n) {
		ll ans = n * (n + 1) / 2;
		REP(j, mat[i].size()) {
			ans -= mat[i][j] * (mat[i][j] + 1) / 2;
		}
		cout << ans << "\n";
	}

	return 0;
}
