#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct fenwick {
  vector<int> tree;
  fenwick(int n = 0) : tree(n + 1) {}
  void update(int i, int val) {
    for (i++; i < tree.size(); i += i & -i) tree[i] += val;
  }
  void update(int i, int j, int val) {
    update(i, val);
    update(j, -val);
  }
  int query(int i) {
    int res = 0;
    for (i++; i; i &= i - 1) res += tree[i];
    return res;
  }
};
const int N = 4e5 + 10;
int n, m, siz[N], dep[N], par[N], head[N], tour[N], in[N], out[N], color[N],
    num_alive;
vector<int> g[N];
vector<pair<int, int>> flip[N];
fenwick alive, weight;
ll light[N], light_square[N], mark[N];
void root(int u = 0, int p = -1, int d = 0) {
  if (p != -1) {
    g[u].erase(find(g[u].begin(), g[u].end(), p));
  }
  siz[u] = 1;
  dep[u] = d;
  par[u] = p;
  for (int &v : g[u]) {
    root(v, u, d + 1);
    siz[u] += siz[v];
    if (siz[v] > siz[g[u][0]]) {
      swap(v, g[u][0]);
    }
  }
  for (int i = 1; i < g[u].size(); i++) {
    int v = g[u][i];
    light[u] += siz[v];
    light_square[u] += 1LL * siz[v] * siz[v];
  }
}
int t = 0;
void split(int u = 0) {
  tour[t] = u;
  weight.update(t, t + 1, siz[u]);
  in[u] = t++;
  for (int v : g[u]) {
    head[v] = (v == g[u][0] ? head[u] : v);
    split(v);
  }
  out[u] = t;
}
ll score(int u) {
  if (g[u].size()) {
    ll h = weight.query(in[g[u][0]]);
    42;
    return h * h + light_square[u];
  } else {
    return 0;
  }
}
int ancestor(int u) {
  42;
  int v = u, w, above = alive.query(in[u]);
  42;
  while (w = par[head[v]], w != -1 && alive.query(in[w]) == above) {
    v = w;
  }
  int lo = in[head[v]] - 1, md, hi = in[v];
  while (hi - lo > 1) {
    md = hi + lo >> 1;
    (alive.query(md) == above ? hi : lo) = md;
  }
  int a = tour[hi];
  42;
  assert(color[a]);
  return a;
}
ll turn_on(int u) {
  42;
  int a = ancestor(u);
  ll res = score(u) - score(a);
  int v = u, w, x = weight.query(in[u]);
  while (head[a] != head[v]) {
    ll h = weight.query(in[head[v]]);
    w = par[head[v]];
    light[w] -= x;
    light_square[w] -= (2 * h - x) * x;
    weight.update(in[head[v]], in[v] + 1, -x);
    v = w;
  }
  weight.update(in[a] + 1, in[v] + 1, -x);
  res += score(a);
  color[u] = true;
  num_alive++;
  alive.update(in[u], out[u], 1);
  42;
  assert(res <= 0);
  return res;
}
ll turn_off(int u) {
  42;
  color[u] = false;
  num_alive--;
  alive.update(in[u], out[u], -1);
  int a = ancestor(u);
  ll res = -score(u) - score(a);
  int v = u, w, x = 1 + light[u];
  if (g[u].size()) {
    x += weight.query(in[g[u][0]]);
  }
  while (head[a] != head[v]) {
    ll h = weight.query(in[head[v]]);
    w = par[head[v]];
    light[w] += x;
    light_square[w] += (2 * h + x) * x;
    weight.update(in[head[v]], in[v] + 1, x);
    v = w;
  }
  weight.update(in[a] + 1, in[v] + 1, x);
  res += score(a);
  42;
  assert(res >= 0);
  return res;
}
void add_edge(int u, int v) {
  g[u].push_back(v);
  g[v].push_back(u);
}
int main() {
  cin >> n >> m;
  alive = fenwick(n + 1);
  weight = fenwick(n + 1);
  for (int u = 1; u <= n; u++) {
    cin >> color[u];
    flip[color[u]].push_back({0, u});
    42;
  }
  add_edge(0, 1);
  for (int i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    add_edge(u, v);
  }
  root();
  split();
  for (int i = 1, u, x; i <= m; i++) {
    cin >> u >> x;
    if (x != color[u]) {
      42;
      flip[color[u]].push_back({i, u});
      flip[x].push_back({i, u});
      color[u] = x;
    }
  }
  fill_n(color, n + 1, 0);
  assert(weight.query(0) == n + 1);
  color[0] = true;
  weight.update(0, 1, -(n + 1));
  alive.update(in[0], out[0], 1);
  mark[0] = 0;
  assert(score(0) == 1LL * n * n);
  for (int x = 1; x <= n; x++) {
    42;
    for (auto &f : flip[x]) {
      int i = f.first, u = f.second;
      ll old = mark[i];
      mark[i] -= (color[u] ? turn_off(u) : turn_on(u));
      42;
    }
    for (auto &f : flip[x]) {
      int i = f.first, u = f.second;
      if (color[u]) {
        turn_off(u);
        color[u] = 0;
      }
    }
  }
  for (int i = 0; i <= m; i++) {
    if (i) {
      mark[i] += mark[i - 1];
    }
    cout << mark[i] << '\n';
  }
}
