#include <stdio.h>
#include <string.h>

int n;
int a[200001];
int b[200001];
int c[200001];
int f[200001];

int dfs( int nd )
{
    int rv = 0;
    f[nd] = 1;

    for( int j=0; j<n-1; j++ ) {
        if( a[j] == nd && f[b[j]] == 0 ) rv += dfs( b[j] );
        if( b[j] == nd && f[a[j]] == 0 ) rv += dfs( a[j] );
    }

    return( rv + 1 );
}

int main( int argc, char *argv[] )
{
    int m;
    int t;

    scanf( "%d", &n );
    for( int i=1; i<=n; i++ )
        scanf( "%d", &c[i] );

    for( int i=0; i<n-1; i++ )
        scanf( "%d %d", &a[i], &b[i] );

    for( int i=1; i<=n; i++ ) {

        t = n * (n+1) / 2;

        for( int j=1; j<=n; j++ ) {
            if( c[j] == i ) f[j] = 1;
            else            f[j] = 0;
        }

        for( int j=1; j<=n; j++ ) {
            if( f[j] == 0 ) {
                m = dfs( j );
                t -= m * (m + 1) / 2;
            }
        }

        printf( "%d\n", t );
    }
}