#include <cstdio>
#include <vector>

using namespace std;

const int MAXN=2e5+10;

typedef long long int ll;

int color[MAXN];
ll N;
vector<int> graph[MAXN];

ll sizes[MAXN];
ll cnt[MAXN];
ll ans[MAXN];

void DFS(int cur,int parent){
    sizes[cur]=1;
    ll temp=cnt[color[cur]];

    for(auto adj:graph[cur]){
        if (adj==parent) continue;
        ll temp=cnt[color[cur]];
        DFS(adj,cur);
        sizes[cur]+=sizes[adj];
        ll diff=cnt[color[cur]]-temp;
        ll sz=sizes[adj]-diff;
        ans[color[cur]]-=sz*(sz-1)/2;
    }

    cnt[color[cur]]=temp+sizes[cur];

}

int main(){
    scanf("%lld",&N);
    for(int i=1;i<=N;i++) scanf("%d",color+i),ans[i]=N*(N-1)/2;

    for(int i=1;i<=N-1;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        graph[s].push_back(e);
        graph[e].push_back(s);
    }

    DFS(1,1);

    for(int c=1;c<=N;c++){
        ll nxt=N-cnt[c];
        ans[c]-=nxt*(nxt-1)/2;
    }

    for(int i=1;i<=N;i++) ans[color[i]]++;

    for(int c=1;c<=N;c++) printf("%lld\n",ans[c]);

    return 0;
}