#include <bits/stdc++.h>
using namespace std;
int read() {
  int X = 0;
  char ch = 0;
  while (ch < 48 || ch > 57) ch = getchar();
  while (ch >= 48 && ch <= 57) X = X * 10 + (ch ^ 48), ch = getchar();
  return X;
}
struct Node {
  int l, r, f, c, pc;
  long long pc2;
  bool col;
  inline void add(int tc) {
    pc += tc;
    pc2 += 1ll * tc * tc;
  }
  inline void del(int tc) {
    pc -= tc;
    pc2 -= 1ll * tc * tc;
  }
} a[400500];
inline void up(int u) { a[u].c = a[a[u].l].c + a[a[u].r].c + a[u].pc + 1; }
inline bool nrt(int u) { return a[a[u].f].l == u || a[a[u].f].r == u; }
inline void rot(int u) {
  int fa = a[u].f, gf = a[fa].f;
  if (a[gf].l == fa) a[gf].l = u;
  if (a[gf].r == fa) a[gf].r = u;
  a[a[fa].f = u].f = gf;
  if (a[fa].l == u) {
    a[a[fa].l = a[u].r].f = fa;
    a[u].r = fa;
  } else {
    a[a[fa].r = a[u].l].f = fa;
    a[u].l = fa;
  }
  up(fa);
  up(u);
}
void splay(int u) {
  while (nrt(u)) {
    int fa = a[u].f, gf = a[fa].f;
    if (nrt(fa) && (a[fa].l == u) == (a[gf].l == fa)) rot(fa);
    rot(u);
  }
}
void access(int x) {
  for (int y = 0; x; x = a[y = x].f) {
    splay(x);
    a[x].add(a[a[x].r].c);
    a[x].del(a[y].c);
    a[x].r = y;
    up(x);
  }
}
int findrt(int x) {
  access(x);
  splay(x);
  while (a[x].l) x = a[x].l;
  splay(x);
  return x;
}
void link(int x, int y) {
  splay(x);
  access(y);
  splay(y);
  a[a[x].f = y].add(a[x].c);
  up(y);
}
void cut(int x, int y) {
  access(x);
  splay(y);
  a[x].f = a[y].r = 0;
  up(y);
}
int qry(int u) {
  int rt = findrt(u);
  splay(rt);
  return a[rt].c - a[rt].pc - 1;
}
int fa[400500];
long long rev(int u) {
  long long ret = 0;
  if (a[u].col) {
    int c = qry(u);
    ret -= 1ll * c * c;
    cut(u, fa[u]);
    access(u);
    c = qry(fa[u]);
    ret += a[u].pc2 + 1ll * c * c;
  } else {
    access(u);
    int c = qry(fa[u]);
    ret -= a[u].pc2 + 1ll * c * c;
    link(u, fa[u]);
    c = qry(u);
    ret += 1ll * c * c;
  }
  a[u].col ^= 1;
  return ret;
}
vector<int> g[400500];
void adl(int f, int t) {
  g[f].push_back(t);
  g[t].push_back(f);
}
void pfs(int u, int _fa) {
  fa[u] = _fa;
  a[u].col = a[u].c = 1;
  link(u, _fa);
  for (int i = 0; i < g[u].size(); i++)
    if (g[u][i] != _fa) pfs(g[u][i], u);
}
long long ans[400500];
struct Data {
  int u, p;
};
vector<Data> b[400500];
void solve(vector<Data> &b) {
  for (int i = 0; i < b.size(); i++) ans[b[i].p] += rev(b[i].u);
  for (int i = 0; i < b.size(); i++)
    if (!a[b[i].u].col) rev(b[i].u);
}
int n, m, col[400500];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) b[col[i] = read()].push_back((Data){i, 0});
  for (int i = 1, f, t; i < n; i++) {
    f = read();
    t = read();
    adl(f, t);
  }
  adl(1, n + 1);
  pfs(1, n + 1);
  long long buf = ans[0] = 1ll * n * n * n;
  for (int i = 1, u, x; i <= m; i++) {
    u = read();
    x = read();
    b[col[u]].push_back((Data){u, i});
    b[col[u] = x].push_back((Data){u, i});
  }
  for (int i = 1; i <= n; i++) solve(b[i]);
  printf("%lld\n", buf - ans[0]);
  for (int i = 1; i <= m; i++) printf("%lld\n", buf - (ans[i] += ans[i - 1]));
  return 0;
}
