#include <bits/stdc++.h>
using namespace std;
const int mxn = 400010;
int rd() {
  int x = 0;
  char c = getchar();
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; x = x * 10 + c - 48, c = getchar())
    ;
  return x;
}
struct nd {
  int key, siz;
  long long num;
  bool tag;
  nd *ls, *rs, *fa;
} pool[mxn], *tpp = pool, *id[mxn], *stk[mxn];
bool noroot(nd *i) { return i->fa && (i->fa->ls == i || i->fa->rs == i); }
void pushup(nd *i) {
  i->siz = i->key;
  if (i->ls) i->siz += i->ls->siz;
  if (i->rs) i->siz += i->rs->siz;
}
void reverse(nd *i) {
  if (i) swap(i->ls, i->rs), i->tag ^= 1;
}
void pushdown(nd *i) {
  if (i->tag) reverse(i->ls), reverse(i->rs), i->tag = 0;
}
void rotate(nd *i) {
  nd *f = i->fa, *s;
  if (noroot(f))
    if (f->fa->ls == f)
      f->fa->ls = i;
    else
      f->fa->rs = i;
  else
    ;
  i->fa = f->fa, f->fa = i;
  if (f->ls == i)
    f->ls = s = i->rs, i->rs = f;
  else
    f->rs = s = i->ls, i->ls = f;
  if (s) s->fa = f;
  pushup(f), pushup(i);
}
void splay(nd *x, int tp = 1) {
  stk[1] = x;
  for (nd *y = x; noroot(y); stk[++tp] = y = y->fa)
    ;
  for (; tp; pushdown(stk[tp--]))
    ;
  for (nd *y; noroot(x); rotate(x))
    if (noroot(y = x->fa)) rotate((y->fa->ls == y) ^ (y->ls == x) ? x : y);
}
void add(nd *x, nd *y) {
  if (x) y->key += x->siz, y->siz += x->siz, y->num += 1ll * x->siz * x->siz;
}
void del(nd *x, nd *y) {
  if (x) y->key -= x->siz, y->siz -= x->siz, y->num -= 1ll * x->siz * x->siz;
}
void access(nd *x) {
  for (nd *y = 0; x; x = (y = x)->fa)
    splay(x), del(y, x), add(x->rs, x), x->rs = y, pushup(x);
}
nd *findroot(nd *x) {
  access(x), splay(x);
  for (pushdown(x); x->ls; pushdown(x = x->ls))
    ;
  return splay(x), x;
}
void link(nd *x, nd *y) { splay(x), access(y), splay(y), add(x, y), x->fa = y; }
void cut(nd *x, nd *y) { access(y), splay(y), splay(x), del(x, y), x->fa = 0; }
int n, m, q, tot, head[mxn], fa[mxn], col[mxn];
long long ans[mxn];
struct ed {
  int to, nxt;
} edge[mxn << 1];
void addedge(int u, int v) {
  edge[++m] = (ed){v, head[u]}, head[u] = m;
  edge[++m] = (ed){u, head[v]}, head[v] = m;
}
void dfs(int u, int f) {
  fa[u] = f;
  for (int i = head[u], v; i; i = edge[i].nxt)
    if ((v = edge[i].to) != f) dfs(v, u);
}
struct opr {
  int typ, x, col, tim;
} a[mxn << 2];
bool operator<(const opr x, const opr y) {
  return x.col < y.col || (x.col == y.col && x.tim < y.tim);
}
int main() {
  n = rd(), q = rd();
  for (int i = 1; i <= n; ++i) a[++tot] = (opr){1, i, col[i] = rd(), 0};
  for (int i = 1, x, y; i < n; ++i) x = rd(), y = rd(), addedge(x, y);
  dfs(1, 0);
  id[0] = ++tpp;
  for (int i = 1; i <= n; ++i) id[i] = ++tpp, tpp->key = 1, tpp->siz = 1;
  for (int i = 1; i <= n; ++i) link(id[i], id[fa[i]]);
  for (int i = 1; i <= q; ++i) {
    int x = rd(), y = rd();
    if (col[x] == y) continue;
    a[++tot] = (opr){0, x, col[x], i};
    a[++tot] = (opr){1, x, col[x] = y, i};
  }
  sort(a + 1, a + tot + 1);
  int lst = 0;
  for (int i = 1; i <= tot; ++i) {
    if (a[i].col > a[i - 1].col) {
      for (int j = i - 1; j > lst; --j)
        if (a[j].typ)
          link(id[a[j].x], id[fa[a[j].x]]);
        else
          cut(id[a[j].x], id[fa[a[j].x]]);
      lst = i - 1;
    }
    if (a[i].typ) {
      nd *x = id[a[i].x], *y = id[fa[a[i].x]], *z;
      if ((z = findroot(x)->rs)) ans[a[i].tim] += 1ll * z->siz * z->siz;
      cut(x, y);
      access(x), ans[a[i].tim] -= x->num;
      if ((z = findroot(y)->rs)) ans[a[i].tim] -= 1ll * z->siz * z->siz;
    } else {
      nd *x = id[a[i].x], *y = id[fa[a[i].x]], *z;
      access(x), ans[a[i].tim] += x->num;
      if ((z = findroot(y)->rs)) ans[a[i].tim] += 1ll * z->siz * z->siz;
      link(x, y);
      if ((z = findroot(x)->rs)) ans[a[i].tim] -= 1ll * z->siz * z->siz;
    }
  }
  for (int i = 1; i <= q; ++i) ans[i] += ans[i - 1];
  for (int i = 0; i <= q; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
