#include <bits/stdc++.h>
using namespace std;
int c[400001];
vector<int> adjList[400001];
vector<pair<int, int> > events[400001];
long long int diff[400002], ans = 0;
int parent[400001];
int doDFS(int u, int p) {
  int i;
  parent[u] = p;
  for (i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (v != p) doDFS(v, u);
  }
  return 0;
}
struct node {
  node *l, *r, *p;
  int k, s, v;
  long long int sq;
};
node *nodes[400001];
int size(node *r) {
  if (r == NULL)
    return 0;
  else
    return r->s;
}
int update(node *r) {
  if (r != NULL) r->s = size(r->l) + size(r->r) + r->v + 1;
  return 0;
}
int isRoot(node *r) {
  return (r->p == NULL) || ((r->p->l != r) && (r->p->r != r));
}
int rotL(node *r) {
  node *n = r->r;
  r->r = n->l;
  if (n->l != NULL) n->l->p = r;
  n->p = r->p;
  if (r->p != NULL) {
    if (r->p->l == r)
      r->p->l = n;
    else if (r->p->r == r)
      r->p->r = n;
  }
  n->l = r, r->p = n;
  update(r), update(n);
  return 0;
}
int rotR(node *r) {
  node *n = r->l;
  r->l = n->r;
  if (n->r != NULL) n->r->p = r;
  n->p = r->p;
  if (r->p != NULL) {
    if (r->p->l == r)
      r->p->l = n;
    else if (r->p->r == r)
      r->p->r = n;
  }
  n->r = r, r->p = n;
  update(r), update(n);
  return 0;
}
int splay(node *n) {
  if (n == NULL) return 0;
  while (!isRoot(n)) {
    if (isRoot(n->p)) {
      if (n == n->p->l)
        rotR(n->p);
      else
        rotL(n->p);
    } else if ((n->p->l == n) && (n->p->p->l == n->p))
      rotR(n->p->p), rotR(n->p);
    else if ((n->p->r == n) && (n->p->p->r == n->p))
      rotL(n->p->p), rotL(n->p);
    else if ((n->p->l == n) && (n->p->p->r == n->p))
      rotR(n->p), rotL(n->p);
    else
      rotL(n->p), rotR(n->p);
  }
  return 0;
}
int access(node *n) {
  node *p = NULL, *o = n;
  while (n != NULL) {
    splay(n);
    n->v += size(n->r), n->sq += (long long int)size(n->r) * size(n->r);
    n->r = p, n->v -= size(p), n->sq -= (long long int)size(p) * size(p);
    update(n), p = n, n = n->p;
  }
  splay(o);
  return 0;
}
int find(int k) {
  node *n = nodes[k];
  access(n);
  while (n->l != NULL) n = n->l;
  splay(n);
  return n->k;
}
int link(int a, int b) {
  int ra = find(a), rb = find(b);
  ans -= nodes[ra]->sq + (long long int)(nodes[ra]->s - nodes[ra]->v - 1) *
                             (nodes[ra]->s - nodes[ra]->v - 1);
  ans -= nodes[rb]->sq + (long long int)(nodes[rb]->s - nodes[rb]->v - 1) *
                             (nodes[rb]->s - nodes[rb]->v - 1);
  access(nodes[a]);
  nodes[a]->p = nodes[b];
  nodes[b]->v += nodes[a]->s,
      nodes[b]->sq += (long long int)nodes[a]->s * nodes[a]->s;
  access(nodes[a]);
  rb = find(b);
  ans += nodes[rb]->sq + (long long int)(nodes[rb]->s - nodes[rb]->v - 1) *
                             (nodes[rb]->s - nodes[rb]->v - 1);
  return 0;
}
int cut(int k) {
  node *n = nodes[k];
  int r = find(k);
  ans -= nodes[r]->sq + (long long int)(nodes[r]->s - nodes[r]->v - 1) *
                            (nodes[r]->s - nodes[r]->v - 1);
  access(n);
  n->l->p = NULL;
  r = n->l->k;
  n->l = NULL;
  update(n), access(n);
  r = find(r);
  ans += nodes[r]->sq + (long long int)(nodes[r]->s - nodes[r]->v - 1) *
                            (nodes[r]->s - nodes[r]->v - 1);
  ans += nodes[k]->sq + (long long int)(nodes[k]->s - nodes[k]->v - 1) *
                            (nodes[k]->s - nodes[k]->v - 1);
  return 0;
}
int main() {
  int i;
  int n, m, u, v;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++)
    scanf("%d", &c[i]), events[c[i]].push_back(make_pair(0, i));
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d", &u, &v);
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &u, &v);
    events[c[u]].push_back(make_pair(i, -u));
    c[u] = v;
    events[c[u]].push_back(make_pair(i, u));
  }
  for (i = 1; i <= n; i++) events[c[i]].push_back(make_pair(m + 1, -i));
  int j;
  doDFS(1, 0);
  for (i = 0; i <= n; i++) {
    nodes[i] = new node;
    nodes[i]->l = nodes[i]->r = nodes[i]->p = NULL;
    nodes[i]->k = i, nodes[i]->s = 1, nodes[i]->v = nodes[i]->sq = 0;
  }
  for (i = 1; i <= n; i++) link(i, parent[i]);
  for (i = 1; i <= n; i++) {
    for (j = 0; j < events[i].size(); j++) {
      diff[(j == 0) ? 0 : events[i][j - 1].first] += ans;
      diff[events[i][j].first] -= ans;
      if (events[i][j].second > 0)
        cut(events[i][j].second);
      else
        link(-events[i][j].second, parent[-events[i][j].second]);
    }
    if (!events[i].empty())
      diff[events[i].back().first] += ans;
    else
      diff[0] += (long long int)n * n;
  }
  for (i = 1; i <= m; i++) diff[i] += diff[i - 1];
  for (i = 0; i <= m; i++)
    printf("%I64d\n", (long long int)n * n * n - diff[i]);
  return 0;
}
