#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MAX_N = 2e5+7;

ll N;
vvl G(MAX_N);
vl cs(MAX_N), tree_size(MAX_N), color_cnts(MAX_N,0);
vl ans(MAX_N);

ll nc2(ll x) { return x*(x-1)/2; }

void calc_size(int v, int par = -1) {
    tree_size[v] = 1;
    for (auto to : G[v]) {
        if (to == par) continue;
        calc_size(to, v);
        tree_size[v] += tree_size[to];
    }
}
void dfs(int v, int par = -1) {
    ll prev_cnt = color_cnts[cs[v]];
    for (auto to : G[v]) {
        if (to == par) continue;
        ll prev = color_cnts[cs[v]];
        dfs(to, v);
        ll diff = color_cnts[cs[v]] - prev;
        ll cnt = tree_size[to] - diff;
        // cerr << v << "->" << to << ": " << cnt << endl;
        ans[cs[v]] -= nc2(cnt);
    }
    color_cnts[cs[v]] = prev_cnt + tree_size[v];
}

int main() {
    cin >> N;
    ans.assign(MAX_N, nc2(N));
    rep(i,N) cin >> cs[i+1], ans[cs[i+1]]++;
    rep(i,N-1) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    calc_size(1);
    dfs(1);
    rep(c,N) ans[c+1] -= nc2(N-color_cnts[c+1]);
    rep(i,N) cerr << ans[i+1] << endl;
    rep(i,N) cout << ans[i+1] << endl;
    return 0;
}
