#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

const int N_MAX = 2e5;
int N;
int C[N_MAX];
int D[N_MAX];
int W[N_MAX];

struct P{
    int v,d;
    bool operator<(const P &a) const {return d<a.d;}
};

//-------------------------------------------------
//--Heavy Light Decomposition
//-------------------------------------------------
class HLD
{
private:
    using Graph = ::std::vector<::std::vector<int> >;
    int n;
    Graph g;
    ::std::vector<int> par, weight, depth;
    ::std::vector<int> head;
    ::std::vector<int> next;
    ::std::vector<int> chain, at;
    ::std::vector<::std::vector<int> > chains;
    vector<unordered_map<int,vi> > Maps;
    void init(){
        par.resize(n);
        weight.resize(n);
        depth.resize(n);
        next.resize(n);
        chain.resize(n);
        at.resize(n);
        head.resize(n);
    }
    void dfs(Graph &g_){
        par[0] = -1;
        depth[0] = 0;
        using P = ::std::pair<int,int>;
        ::std::stack<P> st;
        st.emplace(0,0);
        while(!st.empty()){
            int v = st.top().first;
            int &idx = st.top().second;
            if (idx < g_[v].size()){
                int u = g_[v][idx++];
                if (u==par[v]) continue;
                par[u] = v;
                depth[u] = depth[v]+1;
                st.emplace(u,0);
            }else{
                st.pop();
                int heavy = 0;
                weight[v] = 1;
                for(auto u:g_[v]){
                    if (u==par[v]) continue;
                    weight[v]+=weight[u];
                    if (weight[u]>heavy){
                        heavy = weight[u];
                        next[v] = u;
                    }
                }
            }
        }
    }
    void bfs(Graph &g_){
        int idx=0;
        using P = ::std::pair<int,int>;
        ::std::queue<P> que;
        que.emplace(0,idx++);
        chains.push_back(::std::vector<int>());
        while(!que.empty()){
            int v,c;
            tie(v,c) = que.front(); que.pop();
            chain[v] = c;
            at[v] = chains[c].size();
            chains[c].push_back(v);
            head[v] = chains[c].front();
            for(auto u:g_[v]){
                if (u==par[v]) continue;
                if (u==next[v]){
                    que.emplace(u,c);
                }else{
                    que.emplace(u,idx++);
                    chains.push_back(::std::vector<int>());
                }
            }
        }
    }
    int climb(int v){return par[head[v]];};
public:
    HLD(Graph &g_):n(g_.size()){
        init();
        build(g_);
    }
    HLD(int n_):n(n_),g(n_){init();}
    void add_edge(int a, int b){
        g[a].push_back(b);
        g[b].push_back(a);
    }
    void build(){
        dfs(g);
        bfs(g);
    }
    void build(Graph &g_){
        dfs(g_);
        bfs(g_);
    }
    int lca(int u, int v){
        while(head[u]!=head[v]){
            if (depth[head[u]] > depth[head[v]]){
                u = climb(u);
            }else{
                v = climb(v);
            }
        }
        return (depth[u]<depth[v])?u:v;
    }
    void build_map(){
        int K = chains.size();
        Maps.resize(K);
        rep(i,K){
            int len = chains[i].size();
            rep(j,len){
                int c = C[chains[i][j]];
                Maps[i][c].pb(j);
            }
        }
    }
    int climb_color(int v){
        int c = C[v];
        int prev = v;
        v = par[v];
        int cur = chain[v];
        while(true){
            if (C[v]==c) return prev;
            auto &vec = Maps[cur][c];
            if (!vec.empty()){
                auto itr = upper_bound(all(vec),at[v]);
                if (itr!=vec.begin()){
                    int idx = *(itr-1);
                    return chains[cur][idx+1];
                }
            }
            if (head[v]==0) break;
            prev = head[v];
            v = climb(v);
            cur = chain[v];
        }
        return 0;
    }
};

void dfs(int v, int p, vector<vi> &G, vector<vector<P>> &vv)
{
    W[v]=1;
    vv[C[v]].pb({v,D[v]});
    for(auto u:G[v]){
        if (u==p) continue;
        D[u]=D[v]+1;
        dfs(u,v,G,vv);
        W[v]+=W[u];
    }
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N;
    rep(i,N) cin>>C[i], C[i]--;
    vector<vi> G(N);
    vector<vector<P> > vv(N);
    rep(i,N-1){
        int a,b; cin>>a>>b; a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    HLD hld(G);
    hld.build_map();
    dfs(0,0,G,vv);
    for(auto &vs:vv) sort(rall(vs));
    // for(auto vs:vv){
    //     int V = vs.size();
    //     rep(i,V){
    //         cout<<vs[i].v+1<<" ";
    //     }cout<<endl;
    // }
    rep(c,N){
        unordered_map<int,int> adjust;
        auto &vs = vv[c];
        int V = vs.size();
        if (V==0){
            cout<<"0\n";
            continue;
        }
        ll ans=(ll)N*(N+1)/2;
        for(auto p:vs){
            int v = p.v;
            for(auto u:G[v]){
                if (D[v]<D[u]){
                    int tmp = W[u];
                    if (adjust.count(u)) tmp-=adjust[u];
                    ans-=(ll)tmp*(tmp+1)/2;
                }
            }
            if (v==0) break;
            int t = hld.climb_color(v);
            adjust[t] += W[v];
        }
        if (C[0]!=c){
            int tmp = W[0];
            if (adjust.count(0)) tmp-=adjust[0];
            ans-=(ll)tmp*(tmp+1)/2;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 96268