#include <iostream>
#include <vector>
#include <functional>
using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> C(N);
    for (int &c: C)
        cin>>c, c--;
    vector<vector<int>> E(N);
    for (int i=0; i<N-1; i++)
    {
        int a, b;
        cin>>a>>b;
        E[a-1].push_back(b-1);
        E[b-1].push_back(a-1);
    }

    vector<long long> A(N, (long long)N*(N+1)/2);
    vector<int> CN(N);
    function<int(int, int)> f = [&](int c, int p)
    {
        int s = 0;
        int sc = 0;
        for (int e: E[c])
            if (e!=p)
            {
                int pre = CN[C[c]];
                int n = f(e, c);
                long long nc = n-(CN[C[c]]-pre);
                A[C[c]] -= nc*(nc+1)/2;
                sc += nc;
                s += n;
            }
        CN[C[c]] += sc+1;
        return s+1;
    };
    f(0, -1);
    for (int c=0; c<N; c++)
    {
        long long t = N-CN[c];
        A[c] -= t*(t+1)/2;
    }
    for (long long a: A)
        cout<<a<<endl;
}
