#include <bits/stdc++.h>
using namespace std;
int n, m, F[400010], fa[400010], ch[400010][2], col[400010], C[400010];
long long cur, s[400010], sv[400010], ss[400010], ssv[400010], ans[400010];
vector<int> E[400010];
struct data {
  int tim, id, fl;
};
vector<data> V[400010];
long long sqr(long long x) { return x * x; }
bool not_rt(int x) { return ch[fa[x]][0] == x || ch[fa[x]][1] == x; }
void up(int x) {
  s[x] = s[ch[x][0]] + s[ch[x][1]] + sv[x] + 1,
  ss[x] = sqr(s[ch[x][0]]) + sqr(s[ch[x][1]]) + ssv[x];
}
void rotate(int x) {
  int y = fa[x], z = fa[y], k = ch[y][1] == x;
  if (not_rt(y)) ch[z][ch[z][1] == y] = x;
  ch[y][k] = ch[x][k ^ 1];
  if (ch[y][k]) fa[ch[y][k]] = y;
  ch[x][k ^ 1] = y, fa[y] = x, fa[x] = z;
  up(y), up(x);
}
void splay(int x) {
  while (not_rt(x)) {
    int y = fa[x], z = fa[y];
    if (not_rt(y)) rotate(((ch[y][1] == x) ^ (ch[z][1] == y)) ? x : y);
    rotate(x);
  }
}
void access(int x) {
  for (int y = 0; x; x = fa[y = x])
    splay(x), sv[x] += s[ch[x][1]] - s[y],
        ssv[x] += sqr(s[ch[x][1]]) - sqr(s[y]), ch[x][1] = y, up(x);
}
int findrt(int x) {
  access(x), splay(x);
  while (ch[x][0]) x = ch[x][0];
  splay(x);
  return x;
}
long long query(int x) {
  int t = findrt(x);
  return C[t] ? sqr(s[ch[t][1]]) : sqr(s[t] - (t == n + 1));
}
void link(int x, int y) {
  access(y), splay(y), splay(x);
  cur = query(y) + ss[x];
  fa[x] = y, sv[y] += s[x], ssv[y] += sqr(s[x]), up(y);
  cur -= query(x);
}
void cut(int x, int y) {
  cur = query(x);
  access(x), splay(x);
  fa[ch[x][0]] = 0, ch[x][0] = 0, up(x);
  cur -= query(y) + ss[x];
}
void init(int u, int Fa) {
  for (int i = 0; i < E[u].size(); i++) {
    int v = E[u][i];
    if (Fa ^ v) F[v] = u, link(v, u), init(v, u);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &col[i]), V[col[i]].push_back((data){0, i, 1}), s[i] = 1;
  for (int i = 1, a, b; i < n; i++)
    scanf("%d%d", &a, &b), E[a].push_back(b), E[b].push_back(a);
  init(1, 0), link(1, F[1] = n + 1), C[n + 1] = 1;
  for (int i = 1, a, b; i <= m; i++) {
    scanf("%d%d", &a, &b);
    V[col[a]].push_back((data){i, a, 0}), col[a] = b,
                                          V[b].push_back((data){i, a, 1});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < V[i].size(); j++) {
      data tt = V[i][j];
      tt.fl ? cut(tt.id, F[tt.id]) : link(tt.id, F[tt.id]);
      ans[tt.tim] += cur, C[tt.id] ^= 1;
    }
    for (int j = V[i].size() - 1; j >= 0; j--) {
      data tt = V[i][j];
      tt.fl ? link(tt.id, F[tt.id]) : cut(tt.id, F[tt.id]), C[tt.id] ^= 1;
    }
  }
  for (int i = 1; i <= m; i++) ans[i] += ans[i - 1];
  for (int i = 0; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}
