#include <bits/stdc++.h>
using namespace std;
const int maxn = 400001;
struct op {
  int t, u;
  op() {}
  op(int t, int u) : t(t), u(u) {}
};
struct node {
  node *prt, *path;
  union {
    struct {
      node *ls, *rs;
    };
    node *ch[2];
  };
  int u;
  bool b, sb;
  int f, sf;
  long long g;
} N[maxn];
void update(node *u);
void rotate(node *u);
void splay(node *u);
node *find_first(node *u);
void expose(node *u);
bool splice(node *u);
void access(node *u);
int getf(node *u);
long long getg(node *u);
long long change(int tu);
long long ans[maxn];
vector<op> ord[maxn];
vector<int> init[maxn];
int cur[maxn];
vector<int> adj[maxn];
int prt[maxn];
int f[maxn];
long long g[maxn];
int n, m;
void dfs(int u);
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++) {
    N[i].prt = N[i].path = NULL;
    N[i].ls = N[i].rs = NULL;
    N[i].b = N[i].sb = 0;
    N[i].u = i;
  }
  N[0].b = N[0].sb = 1;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    init[x].push_back(i);
    cur[i] = x;
  }
  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);
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    N[i].path = &N[prt[i]];
    N[i].sf = N[i].f = f[i];
    N[i].g = g[i];
  }
  N[0].sf = N[0].f = n + 1;
  N[0].g = (long long)n * n;
  for (int i = 1; i <= m; i++) {
    int u, x;
    scanf("%d%d", &u, &x);
    ord[cur[u]].push_back(op(i, u));
    cur[u] = x;
    ord[cur[u]].push_back(op(i, u));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < init[i].size(); j++) {
      int u = init[i][j];
      ans[0] += change(u);
    }
    for (int j = 0; j < ord[i].size(); j++) {
      ans[ord[i][j].t] += change(ord[i][j].u);
    }
    for (int j = ord[i].size() - 1; j >= 0; j--) {
      change(ord[i][j].u);
    }
    for (int j = init[i].size() - 1; j >= 0; j--) {
      change(init[i][j]);
    }
  }
  printf("%lld\n", ans[0]);
  for (int i = 1; i <= m; i++) {
    ans[i] += ans[i - 1];
    printf("%lld\n", ans[i]);
  }
  return 0;
}
void dfs(int u) {
  f[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == prt[u]) continue;
    prt[v] = u;
    dfs(v);
    f[u] += f[v];
    g[u] += (long long)f[v] * f[v];
  }
}
void update(node *u) {
  u->sb = u->b;
  u->sf = u->f;
  if (u->ls) u->sb |= u->ls->sb, u->sf += u->ls->sf;
  if (u->rs) u->sb |= u->rs->sb, u->sf += u->rs->sf;
}
bool relation(node *u) { return u == u->prt->rs; }
void rotate(node *u) {
  swap(u->path, u->prt->path);
  bool rel = relation(u);
  if (u->prt->prt) u->prt->prt->ch[relation(u->prt)] = u;
  u->prt->ch[rel] = u->ch[!rel];
  if (u->ch[!rel]) u->ch[!rel]->prt = u->prt;
  u->ch[!rel] = u->prt;
  u->prt = u->prt->prt;
  u->ch[!rel]->prt = u;
  update(u->ch[!rel]);
  update(u);
}
void splay(node *u) {
  while (u->prt) {
    if (!u->prt->prt) {
      rotate(u);
      break;
    }
    if (relation(u) == relation(u->prt)) {
      rotate(u->prt);
      rotate(u);
    } else {
      rotate(u);
      rotate(u);
    }
  }
}
void expose(node *u) {
  splay(u);
  if (!u->rs) return;
  swap(u->rs->prt, u->rs->path);
  u->rs = find_first(u->rs);
  splay(u->rs);
  if (u->rs->b == 0) {
    int f = getf(u->rs);
    u->f += f;
    u->g += (long long)f * f;
  }
  u->rs = NULL;
  update(u);
}
bool splice(node *u) {
  splay(u);
  if (!u->path) return 0;
  u = find_first(u);
  splay(u);
  expose(u->path);
  if (u->b == 0) {
    int f = getf(u);
    u->path->f -= f;
    u->path->g -= (long long)f * f;
  }
  u->path->rs = u;
  swap(u->path, u->prt);
  update(u->prt);
  return 1;
}
void access(node *u) {
  expose(u);
  while (splice(u))
    ;
}
int bwl(node *u) { return u ? u->sb : 0; }
int fwl(node *u) { return u ? u->sf : 0; }
int getf(node *u) {
  splay(u);
  int ans = u->f;
  if (!u->rs) return ans;
  u = u->rs;
  while (u) {
    if (bwl(u->ls) || u->b)
      u = u->ls;
    else {
      ans += fwl(u->ls) + u->f;
      u = u->rs;
    }
  }
  return ans;
}
node *find_first(node *u) {
  while (u->ls) u = u->ls;
  return u;
}
long long getg(node *u) {
  splay(u);
  long long ans = u->g;
  if (!u->rs) return ans;
  node *mch = find_first(u->rs);
  int f = 0;
  if (mch->b == 0) f = getf(mch);
  ans = ans + (long long)f * f;
  return ans;
}
node *find_p(node *u) {
  access(u);
  splay(u);
  u = u->ls;
  while (1) {
    if (bwl(u->rs))
      u = u->rs;
    else if (!u->b)
      u = u->ls;
    else
      break;
  }
  return u;
}
long long change(int tu) {
  node *u = &N[tu];
  node *p = find_p(u);
  long long ans = -getg(p);
  if (u->b == 0) {
    ans += getg(u);
    splay(u);
    u->b = 1;
    update(u);
  } else {
    ans -= getg(u);
    splay(u);
    u->b = 0;
    update(u);
  }
  ans += getg(p);
  return -ans;
}
