#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
  return data * w;
}
int h[1000005], cnt, n, K;
struct node {
  int to, next;
} w[1000005];
void add(int x, int y) {
  w[++cnt] = {y, h[x]};
  h[x] = cnt;
}
int dep[1000005], f[1000005][2], pr[1000005];
void dfs(int x, int fa) {
  dep[x] = dep[fa] + 1;
  pr[x] = fa;
  for (int i = h[x]; i; i = w[i].next) {
    int y = w[i].to;
    if (y == fa) continue;
    dfs(y, x);
  }
}
struct que {
  int x;
  friend bool operator<(que A, que B) { return dep[A.x] < dep[B.x]; }
};
priority_queue<que> Q;
int c[1000005], st[1000005], suf[1000005], a[1000005];
const int mod = 998244353;
void dfs2(int x, int fa) {
  for (int i = h[x]; i; i = w[i].next) {
    int y = w[i].to;
    if (y == fa) continue;
    dfs2(y, x);
  }
  st[0] = 0;
  for (int i = h[x]; i; i = w[i].next) {
    int y = w[i].to;
    if (y != fa) st[++st[0]] = y;
  }
  suf[st[0] + 1] = 1;
  for (int i = st[0]; i >= 1; i--)
    suf[i] = 1ll * suf[i + 1] * (f[st[i]][0] + f[st[i]][1]) % mod;
  if (a[x])
    f[x][1] = suf[1];
  else {
    f[x][0] = suf[1];
    for (int i = h[x], p = 2, s = 1; i; i = w[i].next) {
      int y = w[i].to;
      if (y == fa) continue;
      f[x][1] = (f[x][1] + 1ll * suf[p] * f[y][1] % mod * s) % mod;
      s = 1ll * s * (f[y][0] + f[y][1]) % mod;
      ++p;
    }
  }
}
int main() {
  suf[0] = 1;
  n = read(), K = read();
  for (int i = 1; i <= n; i++) a[i] = read(), c[a[i]]++;
  for (int i = 1; i <= n - 1; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++)
    if (a[i]) Q.push((que){i});
  while (!Q.empty()) {
    int u = Q.top().x, fa = pr[u];
    Q.pop();
    if (a[u] == a[fa])
      --c[a[u]];
    else if (c[a[u]] != 1) {
      if (a[fa])
        return puts("0"), 0;
      else
        a[fa] = a[u], Q.push((que){fa});
    }
  }
  dfs2(1, 0);
  cout << f[1][1] << '\n';
  return 0;
}
