#include <bits/stdc++.h>
using namespace std;
vector <int> c;
vector <vector <int>> g;
vector <bool> clr,used;


int dfs(int v, int color)
{
    //cout << "_";

    used[v] = true;
    int sum = 1;
    for (auto x:g[v])
        {
            if (!used[x] && c[x]!=color)
                sum+= dfs(x,color);
        }
    return sum;
}



int main()
{

int n;
cin >> n;
c.resize(n);
g.resize(n);
clr.resize(n+1);
used.resize(n);
//int now;
for (int i=0; i<n; i++) {cin >> c[i];}

for (int i=1; i<n; i++)
{
    int a,b;
    cin >> a >> b; a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
}
//cout << "1";

for (int j=1; j<=n; j++)
{
    for (int i=0; i<n; i++) used[i] = false;

    long int sum = 0;
    for (int i=0; i<n; i++)
        {
            //cout << "1";
            if (c[i]!=j && !used[i])
                {int now =  dfs(i,j);
                 sum +=  now * (now+1)/2;
                }
        }

    cout << n*(n+1)/2 - sum << "\n";
}







}






