#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, c[202020];
int cnt[202020];
vi G[202020];
vi G2[202020];
pi Par[202020];
int tot[202020];

void dfs1(int idx, int par, vp& V) {
    auto pre = V[c[idx]];
    Par[idx] = pre;
    for (int i = 0; i < G[idx].size(); i++) {
        int nxt = G[idx][i];
        if (nxt == par)
            continue;
        V[c[idx]] = {idx, i};
        dfs1(nxt, idx, V);
    }
    V[c[idx]] = pre;
}

int dfs2(int idx, int par) {
    int tmp = 1;
    for (int i = 0; i < G[idx].size(); i++) {
        int nxt = G[idx][i];
        if (nxt == par)
            continue;
        int tmp2 = dfs2(nxt, idx);
        tmp += tmp2;
        G2[idx][i] += tmp2;
        //cerr << idx << " " << i << " " << tmp2 << endl;
    }
    if (Par[idx].first == 0) {
        G2[0][c[idx]] -= tmp;
    } else
        G2[Par[idx].first][Par[idx].second] -= tmp;
    //cerr << idx << " " << G2[Par[idx].first][Par[idx].second] << endl;

    for (auto a : G2[idx]) {
        cnt[c[idx]] -= a * (a - 1) / 2 + a;
        //cerr << idx << " " << a << endl;
    }

    return tmp;
}


void solve() {
    Fill(cnt, N * (N - 1) / 2 + N);
    G2[0].resize(N + 10);
    for (auto& a : G2[0])
        a = N;
    vp V(N + 10);
    dfs1(1, 0, V);
    dfs2(1, 0);

    FOR (clr, N) {
        int n = G2[0][clr];
        // cerr << clr << " " << n << endl;
        cnt[clr] -= n * (n - 1) / 2 + n;
        cout << cnt[clr] << endl;
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N;
    FOR (N) {
        cin >> c[i + 1];
        c[i + 1]--;
    }
    FOR (N - 1) {
        int a, b;
        cin >> a >> b;
        G[a].eb(b);
        G[b].eb(a);
        G2[a].eb(0);
        G2[b].eb(0);
    }


    solve();
    return 0;
}


Measured memory_bytes: 51684