#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MX = 200005;
vector<int> to[MX];
int t[MX];
int c[MX];
ll ans[MX];
ll f(ll n) { return n*(n+1)/2;}

int tfs(int v, int p=-1) {
  t[v] = 1;
  for (int u : to[v]) {
    if (u == p) continue;
    t[v] += tfs(u,v);
  }
  return t[v];
}

stack<int> st[MX];
int d[MX], remsz[MX];
void dfs(int v, int p=-1) {
  st[c[v]].push(v);
  for (int u : to[v]) {
    if (u == p) continue;
    d[v] = t[u];
    dfs(u,v);
    ans[c[v]] -= f(d[v]);
  }
  st[c[v]].pop();
  if (st[c[v]].size()) {
    d[st[c[v]].top()] -= t[v];
  } else {
    remsz[c[v]] -= t[v];
  }
}

int main() {
  int n;
  cin >> n;
  rep(i,n) cin >> c[i], c[i]--;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  tfs(0);
  rep(i,n) ans[i] = f(n);
  rep(i,n) remsz[i] = n;
  dfs(0);
  rep(i,n) ans[i] -= f(remsz[i]);
  rep(i,n) cout << ans[i] << endl;
  return 0;
}