#include <bits/stdc++.h>
using namespace std;
template <class node>
struct link_cut_tree {
  bool connected(node* u, node* v) { return lca(u, v) != NULL; }
  int depth(node* u) {
    access(u);
    return get_sz(u->ch[0]);
  }
  node* get_root(node* u) {
    access(u);
    while (u->ch[0]) u = u->ch[0], u->push();
    return access(u), u;
  }
  node* ancestor(node* u, int k) {
    k = depth(u) - k;
    assert(k >= 0);
    for (;; u->push()) {
      int sz = get_sz(u->ch[0]);
      if (sz == k) return access(u), u;
      if (sz < k)
        k -= sz + 1, u = u->ch[1];
      else
        u = u->ch[0];
    }
    assert(0);
  }
  node* lca(node* u, node* v) {
    if (u == v) return u;
    access(u);
    access(v);
    if (!u->p) return NULL;
    u->splay();
    return u->p ?: u;
  }
  void link(node* u, node* v) {
    assert(!connected(u, v));
    make_root(v);
    access(u);
    set_link(v, u, 0);
    v->update();
  }
  void cut(node* u) {
    access(u);
    u->ch[0]->p = NULL;
    u->ch[0] = NULL;
    u->update();
  }
  void cut(node* u, node* v) { cut(depth(u) > depth(v) ? u : v); }
  void make_root(node* u) {
    access(u);
    u->rev ^= 1;
    access(u);
    assert(!u->ch[0] && !u->ch[1]);
  }
  void access(node* u) {
    for (node *v = u, *pre = NULL; v; v = v->p) {
      v->splay();
      if (pre) v->update_vsub(pre, false);
      if (v->ch[1]) v->update_vsub(v->ch[1], true);
      v->ch[1] = pre;
      v->update();
      pre = v;
    }
    u->splay();
    assert(!u->ch[1]);
  }
  node* operator[](int i) { return &data[i]; }
  int operator[](node* i) { return i - &data[0]; }
  vector<node> data;
  link_cut_tree(int n) : data(n) {}
};
template <typename pnode>
struct splay_tree {
  pnode ch[2], p;
  bool rev;
  int sz;
  splay_tree() {
    ch[0] = ch[1] = p = NULL;
    rev = 0;
    sz = 1;
  }
  friend int get_sz(pnode u) { return u ? u->sz : 0; }
  void update() { sz = 1 + get_sz(ch[0]) + get_sz(ch[1]); }
  void push() {
    if (rev) {
      if (ch[0]) ch[0]->rev ^= 1;
      if (ch[1]) ch[1]->rev ^= 1;
      swap(ch[0], ch[1]);
      rev = 0;
    }
  }
  int dir() {
    if (!p) return -2;
    if (p->ch[0] == this) return 0;
    if (p->ch[1] == this) return 1;
    return -1;
  }
  bool is_root() { return dir() < 0; }
  friend void set_link(pnode u, pnode v, int d) {
    if (v) v->p = u;
    if (d >= 0) u->ch[d] = v;
  }
  void rotate() {
    assert(!is_root());
    int x = dir();
    pnode g = p;
    set_link(g->p, static_cast<pnode>(this), g->dir());
    set_link(g, ch[x ^ 1], x);
    set_link(static_cast<pnode>(this), g, x ^ 1);
    g->update();
  }
  void splay() {
    const pnode& self = static_cast<pnode>(this);
    while (!is_root() && !p->is_root()) {
      p->p->push(), p->push(), self->push();
      dir() == p->dir() ? p->rotate() : self->rotate();
      self->rotate();
    }
    if (!is_root()) p->push(), self->push(), self->rotate();
    self->push();
    self->update();
  }
};
struct node : splay_tree<node*> {
  using splay_tree::ch;
  bool col;
  long long sz2, szwup, szwdown, vsz2, vszwup, vszwup2;
  node() : splay_tree() {
    col = 0;
    szwup = 1;
    szwdown = -1;
    sz2 = vsz2 = vszwup = vszwup2 = 0;
  }
  void update() {
    splay_tree::update();
    sz2 = vsz2;
    szwup = !col;
    szwdown = -szwup;
    if (ch[0]) {
      szwup = ch[0]->szwup;
      if (ch[0]->szwdown < 0) {
        szwup += !col;
      } else {
        szwdown = ch[0]->szwdown;
        if (col)
          sz2 += szwdown * szwdown, szwdown = 0;
        else
          ++szwdown;
      }
      sz2 += ch[0]->sz2;
    }
    if (col)
      sz2 += vszwup2;
    else {
      if (szwdown < 0)
        szwup += vszwup;
      else
        szwdown += vszwup;
    }
    if (ch[1]) {
      if (szwdown < 0 && ch[1]->szwdown < 0)
        szwup += ch[1]->szwup;
      else if (szwdown < 0)
        szwup += ch[1]->szwup, szwdown = ch[1]->szwdown;
      else if (ch[1]->szwdown < 0)
        szwdown += ch[1]->szwup;
      else
        sz2 += (szwdown + ch[1]->szwup) * (szwdown + ch[1]->szwup),
            szwdown = ch[1]->szwdown;
      sz2 += ch[1]->sz2;
    }
  }
  void update_vsub(node* v, bool add) {
    const int sg = add ? +1 : -1;
    vsz2 += sg * (v->sz2 + (v->szwdown > 0) * v->szwdown * v->szwdown);
    vszwup += sg * v->szwup;
    vszwup2 += sg * v->szwup * v->szwup;
  }
  void push() { splay_tree::push(); }
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> col(n);
  vector<vector<pair<int, int>>> e(n);
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    --x;
    e[x].push_back({0, i});
    col[i] = x;
  }
  link_cut_tree<node> lct(n + 1);
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    --u, --v;
    lct.link(lct[u], lct[v]);
  }
  lct.link(lct[n], lct[0]);
  for (int i = 1, u, x; i <= q; ++i) {
    cin >> u >> x;
    --u, --x;
    if (col[u] == x) continue;
    e[col[u]].push_back({i, ~u});
    e[x].push_back({i, u});
    col[u] = x;
  }
  auto root = lct[n];
  lct.access(root);
  root->col = true;
  root->update();
  vector<long long> ans(q + 1);
  for (auto& c : e) {
    vector<int> nodes;
    long long last = 0;
    for (auto& i : c) {
      int ru = max(i.second, ~i.second);
      nodes.push_back(ru);
      auto u = lct[ru];
      lct.access(u);
      u->col = i.second >= 0;
      u->update();
      if (i.first > 0 || &i == &c.back() || c[&i - &c[0] + 1].first > 0) {
        ans[i.first] += -last;
        lct.access(root);
        ans[i.first] += (last = (long long)n * n -
                                (root->sz2 + root->szwdown * root->szwdown));
      }
    }
    for (auto i : nodes) {
      auto u = lct[i];
      lct.access(u);
      u->col = false;
      u->update();
    }
  }
  partial_sum(ans.begin(), ans.end(), ans.begin());
  for (auto& i : ans) cout << i << "\n";
  return 0;
}
