#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > qry[400010];
long long res[400010], ans;
set<int> B;
int father[400010], sum[400010], tag[400010], son[400010][2], sta[400010], top;
int cur[400010], pre[400010], head[400010], nxt[400010 * 2], a[400010 * 2],
    edge;
int mx[400010];
long long val[400010];
int read() {
  int tmp = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    tmp = tmp * 10 + c - '0';
    c = getchar();
  }
  return tmp;
}
void create(int u, int v) {
  edge++;
  a[edge] = v;
  nxt[edge] = head[u];
  head[u] = edge;
}
void dfs(int u, int fa) {
  pre[u] = fa;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = a[i];
    if (v != fa) dfs(v, u);
  }
}
bool rela(int x) { return son[father[x]][1] == x; }
bool isroot(int x) { return son[father[x]][1] != x && son[father[x]][0] != x; }
void pushdown(int x) {
  if (tag[x]) {
    int tmp = tag[x], l = son[x][0], r = son[x][1];
    if (l) {
      tag[l] += tmp;
      sum[l] += tmp;
      mx[l] += tmp;
    }
    if (r) {
      tag[r] += tmp;
      sum[r] += tmp;
      mx[r] += tmp;
    }
    tag[x] = 0;
  }
}
void update(int x) { mx[x] = max(max(mx[son[x][0]], mx[son[x][1]]), sum[x]); }
void rotate(int x) {
  int y = father[x], ch = rela(x);
  son[y][ch] = son[x][1 ^ ch];
  if (son[x][1 ^ ch]) father[son[x][1 ^ ch]] = y;
  father[x] = father[y];
  if (son[father[y]][0] == y)
    son[father[y]][0] = x;
  else if (son[father[y]][1] == y)
    son[father[y]][1] = x;
  father[y] = x;
  son[x][1 ^ ch] = y;
  update(y);
  update(x);
}
void splay(int x) {
  int tmp = x;
  while (!isroot(tmp)) {
    sta[++top] = tmp;
    tmp = father[tmp];
  }
  sta[++top] = tmp;
  while (top) {
    pushdown(sta[top]);
    top--;
  }
  while (!isroot(x)) {
    int y = father[x];
    if (isroot(y)) {
      rotate(x);
      return;
    }
    if (rela(x) == rela(y))
      rotate(y);
    else
      rotate(x);
    rotate(x);
  }
}
void access(int u) {
  int tmp = 0;
  while (u) {
    splay(u);
    int yuan = son[u][1], cur = mx[yuan];
    val[u] += (long long)cur * cur;
    son[u][1] = tmp;
    update(u);
    if (tmp) father[tmp] = u;
    cur = mx[tmp];
    val[u] -= (long long)cur * cur;
    tmp = u;
    u = father[u];
  }
}
int get_root(int u) {
  access(u);
  splay(u);
  int res = u;
  while (son[res][0]) res = son[res][0];
  return res;
}
void link(int u) {
  splay(u);
  int tmp = mx[u];
  father[u] = pre[u];
  val[pre[u]] += (long long)tmp * tmp;
  access(pre[u]);
  splay(pre[u]);
  tag[pre[u]] += tmp;
  sum[pre[u]] += tmp;
  mx[pre[u]] += tmp;
}
void cut(int u) {
  access(u);
  splay(u);
  int tmp = sum[u];
  tag[son[u][0]] -= tmp;
  sum[son[u][0]] -= tmp;
  mx[son[u][0]] -= tmp;
  father[son[u][0]] = 0;
  son[u][0] = 0;
  update(u);
}
void change(int u) {
  if (cur[u] == 1) {
    B.insert(u);
    cur[u] = 0;
    int v = get_root(u);
    access(v);
    ans -= val[v];
    cut(u);
    access(u);
    access(v);
    splay(u);
    splay(v);
    ans += val[u] + val[v];
  } else {
    B.erase(u);
    cur[u] = 1;
    int v = get_root(pre[u]);
    access(u);
    access(v);
    ans -= val[u] + val[v];
    link(u);
    access(v);
    ans += val[v];
  }
}
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    cur[i] = x;
    qry[x].push_back(make_pair(i, 0));
  }
  for (int i = 2; i <= n; i++) {
    int u = read(), v = read();
    create(u, v);
    create(v, u);
  }
  dfs(1, n + 1);
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    qry[cur[x]].push_back(make_pair(x, i));
    cur[x] = y;
    qry[cur[x]].push_back(make_pair(x, i));
  }
  for (int i = 1; i <= n + 1; i++) {
    sum[i] = mx[i] = 1;
    cur[i] = 0;
  }
  for (int i = 1; i <= n; i++) change(i);
  for (int i = 1; i <= n; i++) {
    int len = qry[i].size();
    long long pre = ans;
    res[0] += ans;
    for (int j = 0; j <= len - 1; j++) {
      pair<int, int> tmp = qry[i][j];
      change(tmp.first);
      if (j == len - 1 || tmp.second != qry[i][j + 1].second) {
        res[tmp.second] += ans - pre;
        pre = ans;
      }
    }
    while (!B.empty()) change(*(B.begin()));
  }
  for (int i = 0; i <= m; i++) {
    if (i) res[i] += res[i - 1];
    long long tmp = (long long)n * n * n - res[i];
    printf("%lld\n", tmp);
  }
  return 0;
}
