#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400000;
int n, m, c[MAXN + 10];
long long s[MAXN + 10], tot;
class node {
 public:
  int ch[2], siz, fa, vsiz, tsiz;
  long long s2;
} t[MAXN + 10];
bool chosen[MAXN + 10];
void pushup(int x) {
  t[x].siz = t[t[x].ch[0]].siz + t[t[x].ch[1]].siz + 1;
  t[x].tsiz = t[t[x].ch[0]].tsiz + t[t[x].ch[1]].tsiz + 1 + t[x].vsiz;
}
bool isroot(int x) { return t[t[x].fa].ch[0] != x && t[t[x].fa].ch[1] != x; }
int son(int x) { return t[t[x].fa].ch[1] == x; }
void rotate(int x) {
  int y = t[x].fa, z = t[y].fa, ts1 = son(y), ts2 = son(x),
      b = t[x].ch[ts2 ^ 1];
  if (z && !isroot(y)) t[z].ch[ts1] = x;
  if (b) t[b].fa = y;
  t[x].fa = z;
  t[y].fa = x;
  t[x].ch[ts2 ^ 1] = y;
  t[y].ch[ts2] = b;
  pushup(y);
  pushup(x);
}
void splay(int x) {
  while (!isroot(x)) {
    if (!isroot(t[x].fa)) rotate(son(x) == son(t[x].fa) ? t[x].fa : x);
    rotate(x);
  }
}
void access(int x) {
  for (int y = 0; x; y = x, x = t[x].fa) {
    splay(x);
    t[x].vsiz += t[t[x].ch[1]].tsiz;
    t[x].s2 += (long long)t[t[x].ch[1]].tsiz * t[t[x].ch[1]].tsiz;
    t[x].ch[1] = y;
    t[x].vsiz -= t[y].tsiz;
    t[x].s2 -= (long long)t[y].tsiz * t[y].tsiz;
    if (y) t[y].fa = x;
    pushup(x);
  }
}
int findroot(int x) {
  access(x);
  splay(x);
  while (t[x].ch[0]) x = t[x].ch[0];
  splay(x);
  return x;
}
vector<int> v[MAXN + 10];
int fa[MAXN + 10];
void dfs(int np, int fath) {
  fa[np] = fath;
  for (int &x : v[np]) {
    if (x == fath) continue;
    dfs(x, np);
  }
}
void link(int x) {
  int fr = findroot(fa[x]);
  access(fr);
  splay(fr);
  tot -= t[fr].s2 + t[x].s2;
  access(fa[x]);
  splay(fa[x]);
  t[x].fa = fa[x];
  t[fa[x]].ch[1] = x;
  pushup(fa[x]);
  access(fr);
  splay(fr);
  tot += t[fr].s2;
}
void cut(int x) {
  int f = findroot(x);
  access(f);
  tot -= t[f].s2;
  access(x);
  splay(x);
  t[t[x].ch[0]].fa = 0;
  t[x].ch[0] = 0;
  pushup(x);
  access(x);
  access(f);
  tot += t[f].s2 + t[x].s2;
}
set<int> used;
void flip(int x) {
  if (chosen[x])
    cut(x);
  else
    link(x);
  chosen[x] ^= 1;
}
vector<int> st[MAXN + 10];
vector<pair<int, int> > opt[MAXN + 10];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]), st[c[i]].push_back(i);
  for (int i = 1; i <= n + 1; i++) t[i].siz = 1, t[i].tsiz = 1;
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1, n + 1);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (c[x] == y) continue;
    opt[c[x]].push_back(make_pair(i, x));
    opt[y].push_back(make_pair(i, x));
    c[x] = y;
  }
  for (int i = 1; i <= n; i++) flip(i);
  for (int i = 1; i <= n; i++) {
    for (int &x : st[i]) {
      used.insert(x);
      flip(x);
    }
    int lstt = 0;
    long long S = (long long)n * n;
    for (auto &x : opt[i]) {
      s[lstt] += S - tot;
      s[x.first] -= S - tot;
      if (!chosen[x.second])
        used.erase(x.second);
      else
        used.insert(x.second);
      flip(x.second);
      lstt = x.first;
    }
    s[lstt] += S - tot;
    for (auto &x : used) flip(x);
    used.clear();
  }
  for (int i = 1; i <= m; i++) s[i] += s[i - 1];
  for (int i = 0; i <= m; i++) printf("%lld\n", s[i]);
  return 0;
}
