#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 7;
inline int read() {
  int sum = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
inline void write(long long x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
struct miaow {
  int ys;
  int siz, lh, rh;
  long long ssum;
  long long xsum, xsum2;
  int fz;
  int son[2], sfa, xfa;
  miaow(int ls = 0, int rs = 0, int sfa = 0, int xfa = 0, int ys = 0,
        int siz = 1, int lh = 1, int rh = 1, long long ssum = 1,
        long long xsum = 0, long long xsum2 = 0, int fz = 0)
      : sfa(sfa),
        xfa(xfa),
        ys(ys),
        siz(siz),
        lh(lh),
        rh(rh),
        ssum(ssum),
        xsum(xsum),
        xsum2(xsum2),
        fz(fz) {
    son[0] = ls, son[1] = rs;
  }
} t[N];
inline int fx(int x) {
  if (!t[x].sfa) return -1;
  return t[t[x].sfa].son[1] == x;
}
inline void upd(int x) {
  if (t[x].fz) return;
  t[x].siz = t[t[x].son[0]].siz + t[t[x].son[1]].siz + 1 + t[x].xsum;
  t[x].lh =
      t[t[x].son[0]].lh + ((t[t[x].son[0]].lh != t[t[x].son[0]].siz || t[x].ys)
                               ? 0
                               : (1 + t[x].xsum + t[t[x].son[1]].lh));
  t[x].rh =
      t[t[x].son[1]].rh + ((t[t[x].son[1]].rh != t[t[x].son[1]].siz || t[x].ys)
                               ? 0
                               : (1 + t[x].xsum + t[t[x].son[0]].rh));
  t[x].ssum = t[x].lh;
}
inline void pdfz(int x) {
  if (!t[x].fz) return;
  t[x].fz = 0;
  swap(t[x].son[0], t[x].son[1]);
  if (t[x].son[0]) {
    swap(t[t[x].son[0]].lh, t[t[x].son[0]].rh);
    t[t[x].son[0]].ssum = t[t[x].son[0]].lh;
    t[t[x].son[0]].fz ^= 1;
  }
  if (t[x].son[1]) {
    swap(t[t[x].son[1]].lh, t[t[x].son[1]].rh);
    t[t[x].son[1]].ssum = t[t[x].son[1]].lh;
    t[t[x].son[1]].fz ^= 1;
  }
  upd(x);
}
inline void rotate(int x) {
  if (!t[x].sfa) return;
  int y = t[x].sfa, k = fx(x), z = t[y].sfa;
  swap(t[x].xfa, t[y].xfa);
  t[y].son[k] = t[x].son[k ^ 1];
  if (t[x].son[k ^ 1]) t[t[x].son[k ^ 1]].sfa = y;
  if (t[y].sfa) {
    int y2 = t[y].sfa, k2 = fx(y);
    t[y2].son[k2] = x;
  }
  t[x].son[k ^ 1] = y;
  t[x].sfa = t[y].sfa;
  t[y].sfa = x;
  upd(y);
  upd(x);
}
inline void pd2(int x) {
  if (t[x].sfa) pd2(t[x].sfa);
  pdfz(x);
}
inline void splay(int x) {
  pd2(x);
  if (!t[x].sfa) return;
  int y = t[x].sfa, k = fx(x);
  while (y) {
    int z = t[y].sfa;
    if (!z) {
      rotate(x);
      return;
    }
    if (fx(y) == k)
      rotate(y);
    else
      rotate(x);
    rotate(x);
    y = t[x].sfa, k = fx(x);
  }
}
inline void access(int x) {
  splay(x);
  if (t[x].son[1]) {
    t[t[x].son[1]].sfa = 0;
    t[t[x].son[1]].xfa = x;
    t[x].xsum += t[t[x].son[1]].ssum;
    t[x].xsum2 += t[t[x].son[1]].ssum * t[t[x].son[1]].ssum;
    t[x].son[1] = 0;
    upd(x);
  }
  int x2 = x;
  while (t[x].xfa) {
    int y = t[x].xfa;
    splay(y);
    if (t[y].son[1]) {
      t[t[y].son[1]].sfa = 0;
      t[t[y].son[1]].xfa = y;
      t[y].xsum += t[t[y].son[1]].ssum;
      t[y].xsum2 += t[t[y].son[1]].ssum * t[t[y].son[1]].ssum;
    }
    t[y].xsum -= t[x].ssum;
    t[y].xsum2 -= t[x].ssum * t[x].ssum;
    t[y].son[1] = x;
    t[x].sfa = y;
    upd(y);
    t[x].xfa = 0;
    x = y;
  }
}
inline void hg(int x) {
  access(x);
  splay(x);
  swap(t[x].lh, t[x].rh);
  t[x].ssum = t[x].lh;
  t[x].fz ^= 1;
}
inline long long cx(int x, int y) {
  hg(x);
  pdfz(x);
  if (t[x].son[1]) {
    upd(t[x].son[1]);
    t[t[x].son[1]].sfa = 0;
    t[t[x].son[1]].xfa = x;
    t[x].xsum += t[t[x].son[1]].ssum;
    t[x].xsum2 += t[t[x].son[1]].ssum * t[t[x].son[1]].ssum;
    t[x].son[1] = 0;
    upd(x);
  }
  t[x].ys = y;
  upd(x);
  long long sum = (t[x].xsum * t[x].xsum - t[x].xsum2),
            sum2 = t[x].xsum * 2 + 1;
  return sum + sum2;
}
inline long long cz(int x, int y) {
  long long sum = cx(x, y);
  return sum;
}
struct meow {
  int a, b, c, d;
  inline bool operator<(const meow& qwe) const {
    return c == qwe.c ? (a == qwe.a ? d < qwe.d : a < qwe.a) : c < qwe.c;
  }
  meow(int a = 0, int b = 0, int c = 0, int d = 0) : a(a), b(b), c(c), d(d) {}
} q[N * 5];
int js = 1;
struct nya {
  int f, t, l;
  nya(int f = 0, int t = 0, int l = 0) : f(f), t(t), l(l) {}
} imap[N * 2 + 1];
int str[N] = {0}, cou = 1;
inline void jb(int f, int t) {
  imap[cou] = nya(f, t, str[f]);
  str[f] = cou++;
  imap[cou] = nya(t, f, str[t]);
  str[t] = cou++;
}
inline void dfs(int o, int fa) {
  for (int i = str[o]; i; i = imap[i].l) {
    int tt = imap[i].t;
    if (tt == fa) continue;
    dfs(tt, o);
    t[o].xsum += t[tt].ssum;
    t[o].xsum2 += t[tt].ssum * t[tt].ssum;
    t[tt].xfa = o;
  }
  upd(o);
}
int cs[N] = {0}, n, m;
long long ans[N] = {0};
int main() {
  n = read(), m = read();
  int zs = m + 1;
  for (int i = 1; i <= n; ++i) {
    int x = read();
    cs[i] = x;
    q[js] = meow(0, i, x, 1);
    ++js;
  }
  for (int i = 1; i < n; ++i) {
    int x = read(), y = read();
    jb(x, y);
  }
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read();
    q[js] = meow(i, x, cs[x], 0);
    ++js;
    q[js] = meow(i, x, y, 1);
    ++js;
    cs[x] = y;
  }
  for (int i = 1; i <= n; ++i) {
    q[js] = meow(zs, i, cs[i], 0);
    ++js;
  }
  t[0].siz = 0, t[0].lh = 0, t[0].rh = 0, t[0].ssum = 0;
  dfs(1, 0);
  sort(q + 1, q + js);
  int col = 0;
  for (int i = 1; i < js; ++i) {
    int a = q[i].a, b = q[i].b, c = q[i].c, d = q[i].d;
    if (c != col) {
      col = c;
    }
    long long sum = cz(b, d);
    if (d == 0)
      ans[a] -= sum;
    else
      ans[a] += sum;
  }
  write(ans[0]), putchar('\n');
  for (int i = 1; i <= m; ++i) {
    ans[i] += ans[i - 1];
    write(ans[i]);
    putchar('\n');
  }
}
