#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using INT = long long;
static char fjf[20202];
char gc() {
  static char *L = fjf, *R = L;
  if (L == R) {
    int n = fread(fjf, 1, 20202, stdin);
    if (!n) return -1;
    L = fjf, R = L + n;
  }
  return *L++;
}
void gn(int &first) {
  char c;
  while (c = gc(), (c < '0' || '9' < c) && ~c)
    ;
  if (!~c) return;
  for (first = c - 48; c = gc(), '0' <= c && c <= '9';
       first = 10 * first + c - 48)
    ;
}
bool now[404040];
int fa[404040], c[404040];
int pa[404040], son[404040][2];
INT s2[404040], del[404040], ans;
int vir[404040], sz[404040];
vector<pii> vec[404040];
vector<int> adj[404040];
void push_up(int u) { sz[u] = sz[son[u][0]] + sz[son[u][1]] + vir[u] + 1; }
bool is_root(int u) { return son[pa[u]][0] != u && son[pa[u]][1] != u; }
void rot(int first, bool d) {
  int second = pa[first], z = pa[second];
  son[second][!d] = son[first][d];
  pa[son[first][d]] = second, pa[first] = pa[second];
  if (son[z][0] == second)
    son[z][0] = first;
  else if (son[z][1] == second)
    son[z][1] = first;
  pa[second] = first, son[first][d] = second;
  push_up(second);
}
void splay(int first) {
  int second, z;
  bool d;
  while (!is_root(first)) {
    if (is_root(pa[first]))
      rot(first, son[pa[first]][0] == first);
    else {
      second = pa[first], z = pa[second], d = son[z][0] == second;
      son[second][d] == first ? rot(first, !d) : rot(second, d);
      rot(first, d);
    }
  }
  push_up(first);
}
void access(int first) {
  for (int second = 0; first; first = pa[first]) {
    splay(first);
    vir[first] += sz[son[first][1]],
        s2[first] += ((INT)(sz[son[first][1]]) * (sz[son[first][1]]));
    son[first][1] = second, vir[first] -= sz[second],
    s2[first] -= ((INT)(sz[second]) * (sz[second]));
    push_up(second = first);
  }
}
int get_root(int u) {
  access(u), splay(u);
  while (son[u][0]) u = son[u][0];
  return u;
}
void link(int u) {
  splay(u), ans -= ((INT)(sz[son[u][1]]) * (sz[son[u][1]])) + s2[u];
  int first = get_root(fa[u]);
  splay(first);
  int up = sz[son[first][1]];
  ans += ((INT)(up + sz[u]) * (up + sz[u])) - ((INT)(up) * (up));
  pa[u] = fa[u], vir[fa[u]] += sz[u];
  s2[fa[u]] += ((INT)(sz[u]) * (sz[u])), access(u);
}
void cut(int u) {
  int first = get_root(u);
  splay(first);
  int up = sz[son[first][1]];
  ans +=
      s2[u] + ((INT)(up - vir[u] - 1) * (up - vir[u] - 1)) - ((INT)(up) * (up));
  splay(u), pa[son[u][0]] = 0, son[u][0] = 0;
}
void dfs(int u) {
  link(u);
  for (int v : adj[u])
    if (v != fa[u]) {
      fa[v] = u, dfs(v);
    }
}
int main() {
  int n, m;
  gn(n), gn(m);
  for (int i = 1; i <= n; i++) {
    gn(c[i]), vec[c[i]].push_back({i, 0});
  }
  for (int i = 1, u, v; i < n; i++) {
    gn(u), gn(v);
    adj[u].push_back(v), adj[v].push_back(u);
  }
  fa[1] = n + 1, dfs(1);
  for (int i = 1, u; i <= m; i++) {
    gn(u), vec[c[u]].push_back({u, i});
    gn(c[u]), vec[c[u]].push_back({u, i});
  }
  for (int c = 1, u; c <= n; c++) {
    if (vec[c].empty()) {
      del[0] += ((INT)(n) * (n));
      continue;
    }
    INT pre = 0;
    if (vec[c][0].second) pre = ((INT)(n) * (n)), del[0] += pre;
    for (int i = 0, j = 0; i < vec[c].size(); i = j) {
      for (; j < vec[c].size() && vec[c][i].second == vec[c][j].second; j++) {
        u = vec[c][j].first;
        if (now[u] ^= 1)
          cut(u);
        else
          link(u);
      }
      del[vec[c][i].second] += ans - pre, pre = ans;
    }
    for (pii p : vec[c]) {
      u = p.first;
      if (now[u] ^= 1)
        cut(u);
      else
        link(u);
    }
  }
  ans = ((INT)(n) * (n)) * n;
  for (int i = 0; i <= m; i++) {
    printf("%I64d\n", ans -= del[i]);
  }
}
