#include <bits/stdc++.h>
using namespace std;
long long get() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const long long N = 4e5 + 5;
long long n, m, col[N], ans[N], ins[N];
struct Edge {
  long long v, nxt;
} edge[N << 1];
long long head[N], tot;
vector<pair<long long, long long> > q[N];
long long c[N][2], f[N], s[N], si[N], s2i[N], lst[N];
void add(long long u, long long v) {
  edge[++tot] = (Edge){v, head[u]}, head[u] = tot;
}
void dfs(long long u, long long fa) {
  lst[u] = fa;
  for (long long i = head[u]; i; i = edge[i].nxt)
    if (edge[i].v != fa) dfs(edge[i].v, u);
}
long long chk(long long x) { return c[f[x]][1] == x; }
long long nroot(long long x) { return c[f[x]][chk(x)] == x; }
void pushup(long long x) { s[x] = s[c[x][0]] + s[c[x][1]] + si[x] + 1; }
void rotate(long long x) {
  long long y = f[x], z = f[y], k = chk(x), w = c[x][!k];
  if (nroot(y)) c[z][chk(y)] = x;
  c[x][!k] = y, c[y][k] = w;
  if (w) f[w] = y;
  f[y] = x, f[x] = z;
  pushup(y), pushup(x);
}
void splay(long long x) {
  while (nroot(x)) {
    long long y = f[x];
    if (nroot(y)) rotate(chk(x) ^ chk(y) ? x : y);
    rotate(x);
  }
}
void access(long long x) {
  for (long long y = 0; x; x = f[y = x]) {
    splay(x);
    si[x] += s[c[x][1]], s2i[x] += s[c[x][1]] * s[c[x][1]];
    c[x][1] = y, si[x] -= s[c[x][1]], s2i[x] -= s[c[x][1]] * s[c[x][1]];
  }
}
void link(long long x) {
  access(x), splay(x), access(lst[x]), splay(lst[x]),
      f[x] = lst[x], si[f[x]] += s[x], s2i[f[x]] += s[x] * s[x], pushup(f[x]);
}
void cut(long long x) {
  access(x), splay(x), c[x][0] = f[c[x][0]] = 0, pushup(x);
}
long long findroot(long long x) {
  access(x), splay(x);
  while (c[x][0]) x = c[x][0];
  splay(x);
  return x;
}
long long query(long long x) {
  long long rt = c[findroot(x)][1];
  return s[rt] * s[rt];
}
long long update(long long x) {
  long long res = 0;
  if (!ins[x]) {
    res = query(x);
    cut(x), res -= s2i[x] + s[c[x][1]] * s[c[x][1]];
    if (!ins[lst[x]]) res -= query(lst[x]);
  } else {
    res = s2i[x] + s[c[x][1]] * s[c[x][1]];
    if (!ins[lst[x]]) res += query(lst[x]);
    link(x), res -= query(x);
  }
  ins[x] ^= 1;
  return res;
}
signed main() {
  n = get(), m = get();
  for (long long i = 1; i <= n; i++)
    col[i] = get(), q[col[i]].push_back(make_pair(i, 0));
  for (long long i = 1, u, v; i < n; i++)
    u = get(), v = get(), add(u, v), add(v, u);
  dfs(1, n + 1);
  for (long long i = 1; i <= m; i++) {
    long long x = get(), y = get();
    q[col[x]].push_back(make_pair(x, i)),
        q[col[x] = y].push_back(make_pair(x, i));
  }
  for (long long i = 1; i <= n; i++) s[i] = 1;
  for (long long i = 1; i <= n; i++) link(i);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < q[i].size(); j++)
      ans[q[i][j].second] += update(q[i][j].first);
    for (long long j = 0; j < q[i].size(); j++) update(q[i][j].first);
  }
  for (long long i = 0; i <= m; i++)
    ans[i] += ans[i - 1], printf("%lld\n", ans[i]);
  return 0;
}
