#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
    int n;
    vector<T> d;
    BIT(int n = 0):n(n),d(n+1) {}
    void add(int i, T x = 1) {
        for(i++; i <= n; i+= i&-i) {
            d[i] += x;
        }
    }
    T sum (int i) {
        T x = 0;
        for(i++; i; i -= i&-i) {
            x += d[i];
        }
        return x;
    }
    T sum(int l, int r) {
        return sum(r-1) - sum(l-1);
    }
};

const int MX = 200005;
vector<int> to[MX];

int in[MX], out[MX], k = 0;
void DFS(int v, int p = -1) {
    in[v] = k++;
    for (int u : to[v]) {
        if (u == p) continue;
        DFS(u,v);
    }
    out[v] = k;
}

ll choose2(ll n) {return n*(n+1)/2;}

int main()
{
    int N;
    cin >> N;
    vector<int> c(N);
    rep(i,N) cin >> c[i];
    int a, b;
    rep(i,N-1) {
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    DFS(0);
    vector<int> sameColor[MX];
    rep(i, N) sameColor[c[i]-1].push_back(i);
    ll tot = choose2(N);
    BIT<int> d(N);
    rep(i, N) d.add(i,1);
    rep(i, N) {
        ll ans = tot;
        vector<int>& nSC = sameColor[i];
        sort(nSC.begin(), nSC.end(), [&](int a, int b) {
                return in[a] > in[b];
            });
        vector<pint> hist;
        for (int v : nSC) {
            int cnt = 1;
            for (int u : to[v]) {
                if (in[u] < in[v]) continue;
                int num = d.sum(in[u], out[u]);
                ans -= choose2(num);
                cnt += num;
            }
            d.add(in[v], -cnt);
            hist.emplace_back(in[v], cnt);
        }
        ans -= choose2(d.sum(0,N)); // for parent node
        for (auto p : hist) {
            d.add(p.first, p.second);
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 35288