#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
const int MOD = 998244353;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
inline long long ksm(long long x, long long k) {
  long long ret = 1;
  while (k) {
    if (k & 1) ret = ret * x % MOD;
    x = x * x % MOD;
    k >>= 1;
  }
  return ret;
}
int n, K, c[MAXN], cnt[MAXN], fa[MAXN], dep[MAXN];
long long dp[MAXN][2];
struct Edge {
  int v, nxt;
} e[MAXN << 1];
int first[MAXN], eCnt;
inline void AddEdge(int u, int v) {
  e[++eCnt].v = v;
  e[eCnt].nxt = first[u];
  first[u] = eCnt;
}
struct Node {
  int u;
  Node(int _u) : u(_u) {}
  bool operator<(const Node &rhs) const { return dep[u] < dep[rhs.u]; }
};
priority_queue<Node> q;
void DFS0(int u) {
  for (int i = first[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa[u]) continue;
    fa[v] = u;
    dep[v] = dep[u] + 1;
    DFS0(v);
  }
}
void DFS(int u) {
  long long prod = 1;
  for (int i = first[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa[u]) continue;
    DFS(v);
    prod = prod * (dp[v][0] + dp[v][1]) % MOD;
  }
  if (c[u]) {
    dp[u][0] = 0;
    dp[u][1] = prod;
  } else {
    dp[u][0] = prod;
    for (int i = first[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (v == fa[u]) continue;
      dp[u][1] = (dp[u][1] +
                  dp[v][1] * prod % MOD * ksm(dp[v][0] + dp[v][1], MOD - 2)) %
                 MOD;
    }
  }
}
void init() {
  read(n);
  read(K);
  for (int i = 1; i <= n; ++i) {
    read(c[i]);
    ++cnt[c[i]];
  }
  for (int i = 1, u, v; i < n; ++i) {
    read(u);
    read(v);
    AddEdge(u, v);
    AddEdge(v, u);
  }
}
void solve() {
  DFS0(1);
  for (int i = 1; i <= n; ++i) {
    if (c[i]) {
      q.push(Node(i));
    }
  }
  while (!q.empty()) {
    int u = q.top().u;
    q.pop();
    if (c[u] == c[fa[u]]) {
      --cnt[c[u]];
    } else if (cnt[c[u]] > 1) {
      if (!c[fa[u]]) {
        c[fa[u]] = c[u];
        q.push(Node(fa[u]));
      } else {
        printf("0\n");
        return;
      }
    }
  }
  DFS(1);
  printf("%lld\n", dp[1][1]);
}
int main() {
  init();
  solve();
  return 0;
}
