#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }

    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
};

struct Graph
{
    int n;
    vector<vector<int>> g;
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

struct Tree	//create tree(directed) from graph(undirected)
{
    int n;
    int root;
    vector<vector<int>> t;
    vector<int> par;
    vector<int> dpt;
    vector<int> tour;
    vector<int> r[200005];
    vector<int> b;
    
    void init(Graph &g, int root_){
        n = g.n;
        root = root_;
        t.resize(n);
        par.resize(n);
        dpt.resize(n);
        fill(dpt.begin(), dpt.end(), -1);
        queue<int> que;
        par[root] = -1;
        dpt[root] = 0;
        que.push(root);
        while(que.size()){
            int pa = que.front();
            que.pop();
            for(int ch : g.g[pa]){
                if(dpt[ch] == -1){
                    t[pa].push_back(ch);
                    par[ch] = pa;
                    dpt[ch] = dpt[pa] + 1;
                    que.push(ch);
                }
            }
        }
    }

    Tree(){}
    
    Tree(Graph &g, int root_){
        init(g, root_);
    }
    
    vector<int> toposort(){
        typedef pair<int, int> P;
        vector<P> p(n);
        for(int i = 0; i < n; i++) p[i] = P(dpt[i], i);
        sort(p.begin(), p.end(), greater<P>());
        vector<int> res(n);
        for(int i = 0; i < n; i++) res[i] = p[i].second;
        return res;
    }
    
    void dfs(int u, int &k){
        tour[k] = u;
        r[u].push_back(k);
        k++;
        b[k] = b[k - 1] + 1;
        for(int v : t[u]){
            dfs(v, k);
            tour[k] = u;
            r[u].push_back(k);
            k++;
            b[k] = b[k - 1];
        }
    }
    
    void eulertour(){
        tour.resize(n * 2);
        b.resize(n * 2 + 1);
        int k = 0;
        b[k] = 0;
        dfs(0, k);
    }
};

vector<int> e[200005];

int main()
{
    ll n;
    cin >> n;
    int c[200005];
    for(int i = 0; i < n; i++){
        cin >> c[i];
        c[i]--;
    }
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.add_edge(a, b);
        g.add_edge(b, a);
    }
    Tree t(g, 0);
    t.eulertour();
    vector<int> d = t.toposort();
    for(int i = 0; i < n; i++){
        int u = d[i];
        e[c[u]].push_back(u);
    }
    SegmentTree<ll> seg(n * 2 + 1, [](int a, int b){return a + b;}, 0ll);
    for(int i = 0; i < n; i++){
        ll ans = 0;
        for(int u : e[i]){
            ll s = 1;
            for(int j = 0; j < (int)t.r[u].size() - 1; j++){
                ll l = (t.b[t.r[u][j + 1] + 1] - t.b[t.r[u][j] + 1]) - seg.query(t.r[u][j], t.r[u][j + 1] + 1);
                s += l;
                ans += l * (l + 1) / 2;
            }
            seg.update(t.r[u][0], s);
        }
        ll l = n - seg.query(0, n * 2);
        ans += l * (l + 1) / 2;
        cout << n * (n + 1) / 2 - ans << endl;
        for(int u : e[i]){
            seg.update(t.r[u][0], 0);
        }
    }
}


Measured memory_bytes: 74756