#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int p = 0, w = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') p = p * 10 + c - '0', c = getchar();
  return p * w;
}
const int sid = 6e5 + 5;
const int mod = 998244353;
inline void inc(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
inline void dec(int &a, int b) {
  a -= b;
  if (a < 0) a += mod;
}
inline int Inc(int a, int b) { return (a + b >= mod) ? a + b - mod : a + b; }
inline int mul(int a, int b) { return 1ll * a * b % mod; }
int n, k, cnp;
int st[sid][20], f[sid][2], C[sid];
int vis[sid], up[sid], dep[sid], cap[sid], nxt[sid], node[sid];
vector<int> col[sid];
inline void addedge(int u, int v) {
  nxt[++cnp] = cap[u];
  cap[u] = cnp;
  node[cnp] = v;
}
inline void dfs(int o, int fa) {
  for (int i = 1; i <= 19; i++) st[o][i] = st[st[o][i - 1]][i - 1];
  for (int i = cap[o]; i; i = nxt[i])
    if (node[i] != fa) {
      up[node[i]] = o;
      st[node[i]][0] = o;
      dep[node[i]] = dep[o] + 1;
      dfs(node[i], o);
    }
}
inline int lca(int u, int v) {
  if (dep[u] - dep[v] < 0) swap(u, v);
  int d = dep[u] - dep[v];
  for (register int i = 19; i >= 0; i--)
    if (d & (1 << i)) u = st[u][i];
  for (register int i = 19; i >= 0; i--)
    if (st[u][i] != st[v][i]) u = st[u][i], v = st[v][i];
  return (u == v) ? u : st[u][0];
}
inline void dp(int o, int fa) {
  vis[o] = 1;
  f[o][0] = 0;
  f[o][1] = 1;
  if (C[o]) {
    f[o][0] = 1;
    f[o][1] = 0;
    return;
  }
  for (int i = cap[o]; i; i = nxt[i])
    if (node[i] != fa) {
      dp(node[i], o);
      f[o][0] =
          Inc(mul(f[node[i]][0], f[o][1]),
              Inc(mul(f[node[i]][0], f[o][0]), mul(f[node[i]][1], f[o][0])));
      f[o][1] = Inc(mul(f[o][1], f[node[i]][0]), mul(f[o][1], f[node[i]][1]));
    }
}
int main() {
  n = read();
  k = read();
  for (register int i = 1; i <= n; i++) {
    C[i] = read();
    col[C[i]].push_back(i);
  }
  for (register int i = 2; i <= n; i++) {
    int u = read(), v = read();
    addedge(u, v);
    addedge(v, u);
  }
  dfs(1, 0);
  for (register int i = 1; i <= k; i++)
    if (col[i].size()) {
      int anc = col[i][0];
      for (auto x : col[i]) anc = lca(anc, x);
      for (auto x : col[i]) {
        int t = x;
        while (t != anc) {
          t = up[t];
          if (C[t] == i) break;
          if (C[t] == 0) C[t] = i;
          if (C[t] != i) {
            printf("0\n");
            return 0;
          }
        }
      }
    }
  int ret = 1;
  for (register int i = 1; i <= n; i++)
    if (!vis[i] && !C[i]) dp(i, 0), ret = mul(ret, f[i][0]);
  printf("%d\n", ret);
  return 0;
}
