#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int col[N] = {};
long long cnt[N] = {};
long long ans[N] = {};
vector<int> G[N] = {};
long long n;
long long dfs(int u, int f) {
  long long ret = 1, s = 0, tag = cnt[col[u]];
  long long intag = tag;
  for (const int &v : G[u]) {
    if (v == f) continue;
    s = dfs(v, u);
    ret += s;
    long long d = s - (cnt[col[u]] - tag);
    ans[col[u]] -= d * (d - 1) / 2;
    tag = cnt[col[u]];
  }
  cnt[col[u]] = intag + ret;
  return ret;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  fill(ans + 1, ans + 1 + n, n * (n - 1) / 2);
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
    ans[col[i]]++;
  }
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    long long s = n - cnt[i];
    ans[i] -= s * (s - 1) / 2;
    cout << ans[i] << '\n';
  }
  return 0;
}
