#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

vector<int> to[200005];
int c[200005];
int buka[200005];
vector<int> data[200005];
int numcol[200005];

void dfs(int x, int p) {
    if (to[x].size()==1 && to[x][0]==p) return;
    for (int e: to[x]) {
        if (e==p) continue;
        dfs(e, x);
        buka[x] += (buka[e])+1;
    }
}

void dfs2(int x, int p) {
    int color = c[x];
    if (data[color].size()) {
        data[color][data[color].size()-1] -= (buka[x]+1);
    }
    int id = data[color].size()-1;
    for (int e: to[x]) {
        if (e==p) continue;
        data[color].push_back(buka[e]+1);
        //int v = data[color][id];
        //data[color].erase(data[color].begin()+id);
        //data[color].push_back(v);
        //id = data[color].size()-1;
        dfs2(e, x);
    }
}

int main(){
    int n;
    cin >> n;
    
    
    rep(i, n) {
        cin >> c[i];
        c[i]--;
        numcol[c[i]]++;
    }
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }

    dfs(0, -1);
    dfs2(0, -1);

    rep(i, n) {
        /*
        rep(j, data[i].size()) {
            cout << data[i][j] << " ";
        }
        */
        //cout << endl;
        if (data[i].size()==0 && numcol[i]==0) {
            //ll ans2 = numcol[i]*(numcol[i]+1)/2;
            cout << "0" << endl;
            continue;
        }
        ll sum = 0;
        ll ans = 0;
        for (int e: data[i]) {
            ll x = e;
            sum += x;
            ans += x*(x+1)/2;
        }
        ll rem = n - sum - numcol[i];
        ans += rem*(rem+1)/2;
        ll res = n*(n+1)/2 - ans;
        cout << res << endl;
    }

    
    
    
    
    return 0;
}
