#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[1000010];
struct apple {
  long long to, next;
} indexx[1000010];
long long head[1000010], cnt;
void init(long long x, long long y) {
  indexx[++cnt].to = y;
  indexx[cnt].next = head[x];
  head[x] = cnt;
}
bool flag;
long long c[1000010];
long long tmp[1000010];
long long dp[1000010][2];
long long punc[1000010];
vector<long long> q;
void dfs(long long u, long long fa) {
  tmp[u] = a[u] > 0;
  for (long long i = head[u]; i; i = indexx[i].next) {
    long long v = indexx[i].to;
    if (v == fa) continue;
    dfs(v, u);
    if (!a[u])
      a[u] = a[v];
    else if (a[v] && a[u] != a[v]) {
      flag = 1;
    }
    tmp[u] += tmp[v];
  }
  q.clear();
  for (long long i = head[u]; i; i = indexx[i].next) {
    long long v = indexx[i].to;
    if (v != fa) {
      q.push_back(v);
    }
  }
  punc[0] = 1;
  for (long long i = 0; i < q.size(); i++) {
    long long v = q[i];
    punc[i + 1] = (long long)punc[i] % 998244353 *
                  (dp[v][0] % 998244353 + dp[v][1] % 998244353) % 998244353;
  }
  long long siz = q.size();
  if (!siz) {
    if (a[u]) {
      dp[u][1] = 1;
    } else {
      dp[u][0] = 1;
      dp[u][1] = 0;
    }
    if (c[a[u]] == tmp[u]) a[u] = tmp[u] = 0;
    return;
  }
  if (a[u]) {
    dp[u][1] = punc[siz];
  } else {
    dp[u][0] = punc[siz];
    long long tot = 1;
    for (long long i = q.size() - 1; i >= 0; i--) {
      long long v = q[i];
      dp[u][1] = (dp[u][1] +
                  (long long)tot * dp[v][1] % 998244353 * punc[i] % 998244353) %
                 998244353;
      tot = (long long)tot * (dp[v][0] + dp[v][1]) % 998244353;
    }
  }
  if (tmp[u] == c[a[u]]) tmp[u] = a[u] = 0;
}
signed main() {
  scanf("%I64d%I64d", &n, &k);
  for (long long i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    c[a[i]]++;
  }
  for (long long i = 1; i < n; i++) {
    long long x, y;
    scanf("%I64d%I64d", &x, &y);
    init(x, y);
    init(y, x);
  }
  dfs(1, 0);
  printf("%I64d\n", flag ? 0 : dp[1][1]);
}
