// Code By H~$~C

import std.stdio;
import std.math, std.uni, std.format, std.bigint;
import std.array, std.string, std.container, std.range, std.typecons;
import std.algorithm, std.conv, std.functional, std.random;

immutable Maxn = 200005;

int n;
int[Maxn] c;
int[][Maxn] g;
long[Maxn] ans;
int[Maxn] sz, num;

void dfs(int u, int fa) {
  int col = c[u];
  int bef = num[col];
  sz[u] = 1;
  foreach(v; g[u]) {
    if (v == fa) continue;
    int pre = num[col];
    dfs(v, u);
    int vcol = sz[v] - (num[col] - pre);
    ans[col] -= cast(long)(vcol + 1) * vcol / 2;
    sz[u] += sz[v];
  }
  num[col] = bef + sz[u];
}

void _Main() {
  read(n);
  foreach(i; 0 .. n)
    read(c[i]), c[i]--;
  foreach(i; 1 .. n) {
    int u, v;
    read(u, v);
    --u, --v;
    g[u] ~= v;
    g[v] ~= u;
  }
  foreach(i; 0 .. n)
    ans[i] = cast(long)(n + 1) * n / 2;
  dfs(0, -1);
  foreach(i; 0 .. n) {
    int rest = n - num[i];
    (ans[i] -= cast(long)(rest + 1) * rest / 2).writeln;
  }
}

class EOFException : Throwable {
  this() { super("------ EOF Error!"); }
}
string[] tokens;
string readToken() {
  for (; tokens.empty; ) {
    if (stdin.eof) { throw new EOFException; }
    tokens = readln.split;
  }
  auto token = tokens.front;
  tokens.popFront;
  return token;
}
void read(T...)(ref T x) {
  foreach(i, ref y; x)
    y = readToken.to!(T[i]);
}

void main(string[] args) {
  try {
    int tests = 1;
//    read(tests);
    foreach (test; 0 .. tests) _Main();
  } catch(EOFException e) {
  }
}
