#include <bits/stdc++.h>
long long fa[400010], ch[400010][2];
long long si[400010], size[400010], G[400010];
bool son(long long x) { return ch[fa[x]][1] == x; }
bool isroot(long long x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
void pushup(long long x) {
  size[x] = size[ch[x][0]] + size[ch[x][1]] + si[x] + 1;
}
void Rotate(long long x) {
  if (!x || !fa[x] || isroot(x)) return;
  long long faz = fa[x], fazz = fa[faz], g = son(x);
  fa[x] = fazz;
  if (!isroot(faz)) ch[fazz][son(faz)] = x;
  fa[ch[x][!g]] = faz;
  ch[faz][g] = ch[x][!g];
  fa[faz] = x;
  ch[x][!g] = faz;
  pushup(faz);
  pushup(x);
}
void splay(long long node) {
  while (!isroot(node)) {
    if (!isroot(fa[node]))
      if (son(fa[node]) ^ son(node))
        Rotate(node);
      else
        Rotate(fa[node]);
    Rotate(node);
  }
  pushup(node);
}
void access(long long x) {
  for (long long y = 0; x; y = x, x = fa[x]) {
    splay(x);
    si[x] += size[ch[x][1]];
    si[x] -= size[y];
    G[x] += 1ll * size[ch[x][1]] * size[ch[x][1]];
    G[x] -= 1ll * size[y] * size[y];
    ch[x][1] = y;
    pushup(x);
  }
}
void link(long long x, long long y) {
  access(x);
  splay(x);
  access(y);
  splay(y);
  fa[x] = y;
  si[y] += size[x];
  G[y] += 1ll * size[x] * size[x];
  pushup(y);
}
long long find(long long x) {
  access(x);
  splay(x);
  while (ch[x][0]) x = ch[x][0];
  return x;
}
void cut(long long x, long long y) {
  access(x);
  splay(y);
  ch[y][1] = fa[x] = 0;
  pushup(y);
}
long long head[400010], nxt[800001], b[800001], k, n, m, c[400010], Fa[400010];
bool col[400010];
std::vector<std::pair<long long, long long> > que[400001];
void push(long long s, long long t) {
  nxt[++k] = head[s];
  head[s] = k;
  b[k] = t;
}
void dfs(long long x, long long f) {
  Fa[x] = fa[x] = f;
  size[x] = 1;
  for (long long i = head[x]; i; i = nxt[i])
    if (b[i] != f) {
      dfs(b[i], x);
      size[x] += size[b[i]];
      G[x] += 1ll * size[b[i]] * size[b[i]];
    }
  si[x] = size[x] - 1;
}
long long ans[400010];
long long f(long long x) {
  return 1ll * (size[ch[x][0]] + size[ch[x][1]]) *
             (size[ch[x][0]] + size[ch[x][1]]) +
         G[x];
}
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", c + i), que[c[i]].push_back(std::make_pair(0, i));
  for (long long i = 1, u, v; i < n; i++)
    scanf("%lld%lld", &u, &v), push(u, v), push(v, u);
  push(n + 1, 1);
  dfs(n + 1, 0);
  for (long long i = 1, u, col; i <= m; i++) {
    scanf("%lld%lld", &u, &col);
    if (c[u] == col) continue;
    que[col].push_back(std::make_pair(i, u));
    que[c[u]].push_back(std::make_pair(i, -u));
    c[u] = col;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < (long long)que[i].size(); j++) {
      long long t = que[i][j].first;
      if (que[i][j].second > 0) {
        long long u = que[i][j].second, v = Fa[u];
        col[u] ^= 1;
        access(u);
        splay(u);
        long long sz = size[u] - si[find(u)] - 1;
        splay(find(u));
        ans[t] += 1ll * sz * sz;
        cut(u, v);
        ans[t] -= f(u) + 1ll * (sz - size[u]) * (sz - size[u]);
      } else {
        long long u = -que[i][j].second, v = Fa[u];
        col[u] ^= 1;
        splay(u);
        long long tm = size[u];
        ans[t] += f(u);
        link(u, v);
        access(u);
        splay(u);
        long long sz = size[u] - si[find(u)] - 1;
        ans[t] -= 1ll * sz * sz - 1ll * (sz - tm) * (sz - tm);
        splay(find(u));
      }
    }
    for (long long j = 0; j < (long long)que[i].size(); j++) {
      long long u = que[i][j].second;
      if (u < 0) u = -u;
      if (col[u]) link(u, Fa[u]), col[u] = 0;
    }
  }
  for (long long i = 1; i <= m; i++) ans[i] += ans[i - 1];
  for (long long i = 0; i <= m; i++) printf("%lld\n", ans[i]);
}
