#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  static char c;
  int f = 0;
  while (!isdigit(c = getchar()))
    if (c == '-') f = 1;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
  if (f) x = -x;
}
void read(long long &x) {
  static char c;
  int f = 0;
  while (!isdigit(c = getchar()))
    if (c == '-') f = 1;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
  if (f) x = -x;
}
void read(unsigned int &x) {
  static char c;
  while (!isdigit(c = getchar()))
    ;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
}
void read(unsigned long long &x) {
  static char c;
  while (!isdigit(c = getchar()))
    ;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
}
void chkmax(int &x, int y) {
  if (y > x) x = y;
}
void chkmin(int &x, int y) {
  if (y < x) x = y;
}
void chkmax(long long &x, long long y) {
  if (y > x) x = y;
}
void chkmin(long long &x, long long y) {
  if (y < x) x = y;
}
void chkmax(unsigned int &x, unsigned int y) {
  if (y > x) x = y;
}
void chkmin(unsigned int &x, unsigned int y) {
  if (y < x) x = y;
}
void chkmax(unsigned long long &x, unsigned long long y) {
  if (y > x) x = y;
}
void chkmin(unsigned long long &x, unsigned long long y) {
  if (y < x) x = y;
}
long long sq(long long x) { return x * x; }
const int N = 4e5 + 10;
int n, m;
vector<int> Edge[N];
int _Fat[N], col[N];
long long def[N], _def;
int cnt;
vector<pair<int, int> > O[N];
namespace LCT {
struct Node {
  int fat, son[2];
  long long alls, ligs, ligs2, alls2;
} t[N];
void Init() {
  for (int i = 1; i <= n + 1; ++i)
    t[i].fat = t[i].son[0] = t[i].son[1] = t[i].ligs = t[i].ligs2 = 0,
    t[i].alls = t[i].alls2 = 1;
}
void Update(int now) {
  int ls = t[now].son[0], rs = t[now].son[1];
  t[now].alls = t[ls].alls + t[rs].alls + t[now].ligs + 1;
  t[now].alls2 = sq(t[now].alls);
}
int NoRt(int now) {
  for (int D : {0, 1})
    if (t[t[now].fat].son[D] == now) return true;
  return false;
}
int GDir(int now) { return t[t[now].fat].son[1] == now; }
void Rorate(int now) {
  int Fat = t[now].fat, Gat = t[Fat].fat;
  int Fdir = GDir(now), Gdir = GDir(Fat);
  if (NoRt(Fat)) t[Gat].son[Gdir] = now;
  t[now].fat = Gat, t[Fat].fat = now;
  t[t[now].son[Fdir ^ 1]].fat = Fat;
  t[Fat].son[Fdir] = t[now].son[Fdir ^ 1];
  t[now].son[Fdir ^ 1] = Fat;
  Update(Fat), Update(now);
}
void Splay(int now) {
  while (NoRt(now)) {
    int Fat = t[now].fat;
    if (NoRt(Fat)) (GDir(now) ^ GDir(Fat)) ? Rorate(now) : Rorate(Fat);
    Rorate(now);
  }
}
void Access(int now) {
  for (int i = 0; now; now = t[i = now].fat) {
    int &rs = t[now].son[1];
    Splay(now);
    t[now].ligs -= t[i].alls, t[now].ligs2 -= t[i].alls2;
    t[now].ligs += t[rs].alls, t[now].ligs2 += t[rs].alls2;
    rs = i, Update(now);
  }
}
int Findroot(int now) {
  Access(now), Splay(now);
  while (t[now].son[0]) now = t[now].son[0];
  return Splay(now), now;
}
void Link(int now, long long &res) {
  Splay(now), res -= t[now].ligs2 + t[t[now].son[1]].alls2;
  int Fat = _Fat[now];
  int Rt = Findroot(Fat);
  Splay(Rt), res -= t[t[Rt].son[1]].alls2;
  Splay(Fat), t[now].fat = Fat;
  Update(now), t[Fat].ligs += t[now].alls, t[Fat].ligs2 += t[now].alls2,
      Update(Fat);
  Access(now), Splay(Rt), res += t[t[Rt].son[1]].alls2;
}
void Cut(int now, long long &res) {
  Access(now), res += t[now].ligs2;
  int Fat = _Fat[now];
  int Rt = Findroot(Fat);
  Access(now), Splay(Rt), res -= t[t[Rt].son[1]].alls2;
  Splay(now), t[now].son[0] = t[t[now].son[0]].fat = 0, Update(Fat);
  Splay(Rt), res += t[t[Rt].son[1]].alls2;
}
};  // namespace LCT
using namespace LCT;
void Modify(int now, long long &res) {
  if (t[now].fat)
    Cut(now, res);
  else
    Link(now, res);
}
void Work() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) {
    read(col[i]);
    O[col[i]].push_back(make_pair(i, 0));
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    read(u), read(v);
    Edge[u].push_back(v), Edge[v].push_back(u);
  }
  const auto &GetF = []() -> void {
    function<void(int, int)> dfs;
    dfs = [&dfs](int now, int fa) -> void {
      _Fat[now] = fa;
      for (int v : Edge[now])
        if (v != fa) dfs(v, now);
    };
    dfs(1, n + 1);
  };
  GetF();
  for (int i = 1; i <= m; ++i) {
    int u, c;
    read(u), read(c);
    O[col[u]].push_back(make_pair(u, i));
    O[col[u] = c].push_back(make_pair(u, i));
  }
  Init();
  for (int i = 1; i <= n; ++i) Modify(i, _def);
  for (int i = 1; i <= n; ++i) {
    if (!O[i].size()) continue;
    for (int o = 0; o < O[i].size(); ++o) {
      int now = O[i][o].first, tim = O[i][o].second;
      Modify(now, def[tim]);
    }
    for (int o = O[i].size() - 1; ~o; --o) {
      int now = O[i][o].first;
      Modify(now, _def);
    }
  }
  long long Ans = 0;
  for (int i = 0; i <= m; ++i) printf("%lld\n", Ans -= def[i]);
}
int main() { Work(); }
