#include <bits/stdc++.h>
using ll = long long;
int lson[400005], rson[400005], fa[400005], sz[400005], val[400005];
ll sqr[400005];
bool rev[400005];
inline bool isrt(int u) { return lson[fa[u]] != u && rson[fa[u]] != u; }
inline void push_down(int u) {
  if (u && rev[u]) {
    std::swap(lson[u], rson[u]);
    rev[lson[u]] ^= 1;
    rev[rson[u]] ^= 1;
    rev[u] = false;
  }
}
inline void push_up(int u) {
  sz[u] = val[u] + 1;
  if (lson[u]) sz[u] += sz[lson[u]];
  if (rson[u]) sz[u] += sz[rson[u]];
}
inline void rotate(int u) {
  int v = fa[u];
  int *same = lson[v] == u ? lson : rson, *ano = lson[v] == u ? rson : lson;
  fa[u] = fa[v];
  if (!isrt(v)) (lson[fa[v]] == v ? lson : rson)[fa[v]] = u;
  same[v] = ano[u];
  fa[ano[u]] = v;
  ano[u] = v;
  fa[v] = u;
  push_up(v);
  push_up(u);
}
inline void splay(int u) {
  static int st[400005];
  int tp = 0;
  st[tp++] = u;
  for (int i = u; !isrt(i); i = fa[i]) st[tp++] = fa[i];
  while (tp--) push_down(st[tp]);
  while (!isrt(u)) {
    int v = fa[u];
    if (!isrt(v)) {
      if ((lson[fa[v]] == v) ^ (lson[v] == u))
        rotate(u);
      else
        rotate(v);
    }
    rotate(u);
  }
}
inline void access(int u) {
  for (int v = 0; u; v = u, u = fa[u]) {
    splay(u);
    if (rson[u]) {
      val[u] += sz[rson[u]];
      sqr[u] += (ll)sz[rson[u]] * (ll)sz[rson[u]];
    }
    rson[u] = v;
    if (v) {
      val[u] -= sz[v];
      sqr[u] -= (ll)sz[v] * (ll)sz[v];
    }
    push_up(u);
  }
}
inline int get_rt(int u) {
  access(u);
  splay(u);
  while (lson[u]) u = lson[u];
  splay(u);
  return u;
}
int par[400005], col[400005];
std::vector<int> adj[400005];
std::vector<std::pair<int, int> > vec[400005];
ll lazy[400005], ans;
bool vis[400005];
void add(int u) {
  int v = par[u++] + 1;
  splay(u);
  ans -= sqr[u] + (ll)sz[rson[u]] * sz[rson[u]];
  int w = get_rt(v);
  access(u);
  splay(w);
  ans -= (ll)sz[rson[w]] * sz[rson[w]];
  fa[u] = v;
  splay(v);
  val[v] += sz[u];
  sqr[v] += (ll)sz[u] * sz[u];
  push_up(v);
  access(u);
  splay(w);
  ans += (ll)sz[rson[w]] * sz[rson[w]];
}
void del(int u) {
  int v = par[u++] + 1;
  access(u);
  ans += sqr[u];
  int w = get_rt(v);
  access(u);
  splay(w);
  ans -= (ll)sz[rson[w]] * sz[rson[w]];
  splay(u);
  lson[u] = fa[lson[u]] = 0;
  push_up(u);
  splay(w);
  ans += (ll)sz[rson[w]] * sz[rson[w]];
}
void dfs(int u, int f) {
  par[u] = f;
  for (int v : adj[u]) {
    if (v != f) dfs(v, u);
  }
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    scanf("%d", col + i);
    vec[--col[i]].emplace_back(i, 0);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
  for (int i = 0; i < q; i++) {
    int u, c;
    scanf("%d%d", &u, &c);
    u--;
    vec[col[u]].emplace_back(u, i + 1);
    col[u] = --c;
    vec[col[u]].emplace_back(u, i + 1);
  }
  dfs(0, n);
  for (int i = 1; i <= n + 1; i++) sz[i] = 1;
  for (int i = 0; i < n; i++) add(i);
  for (int i = 0; i < n; i++) {
    if (vec[i].empty()) {
      lazy[0] += (ll)n * n;
      continue;
    }
    ll lst = 0;
    if (vec[i][0].second) {
      lazy[0] += (ll)n * n;
      lst = (ll)n * n;
    }
    for (int j = 0; j < vec[i].size(); j++) {
      int u = vec[i][j].first;
      vis[u] ^= 1;
      (vis[u] ? del : add)(u);
      if (j + 1 == vec[i].size() || vec[i][j].second != vec[i][j + 1].second) {
        lazy[vec[i][j].second] += ans - lst;
        lst = ans;
      }
    }
    for (int j = vec[i].size() - 1; j >= 0; j--) {
      int u = vec[i][j].first;
      vis[u] ^= 1;
      (vis[u] ? del : add)(u);
    }
  }
  ans = (ll)n * n * n;
  for (int i = 0; i <= q; i++) {
    ans -= lazy[i];
    printf("%lld\n", ans);
  }
  return 0;
}
