#include <bits/stdc++.h>
using namespace std;
int val[300005];
vector<int> v[300005];
vector<int> color[300005];
int dep[300005];
int p[300005];
void dfs(int first, int f) {
  p[first] = f;
  dep[first] = dep[f] + 1;
  for (auto it : v[first]) {
    if (it != f) {
      dfs(it, first);
    }
  }
}
int mod = 998244353;
long long dp[300005][2];
int vis[300005];
void dfs2(int first, int f) {
  vis[first] = 1;
  if (val[first]) {
    dp[first][1] = 1;
    return;
  }
  dp[first][0] = 1;
  vector<long long> value1, value2;
  value1.push_back(1);
  value2.push_back(1);
  for (auto it : v[first]) {
    if (it != f) {
      dfs2(it, first);
      dp[first][0] *= (dp[it][0] + dp[it][1]);
      value1.push_back(dp[it][0] + dp[it][1]);
      value2.push_back(dp[it][1]);
      dp[first][0] %= mod;
    }
  }
  value1.push_back(1);
  value2.push_back(1);
  vector<long long> pre, suf(value1.size());
  pre.push_back(1);
  for (int i = 1; i < value1.size(); i++) {
    pre.push_back(pre[i - 1] * value1[i] % mod);
  }
  suf[suf.size() - 1] = 1;
  for (int i = suf.size() - 2; i >= 0; i--) {
    suf[i] = suf[i + 1] * value1[i] % mod;
  }
  dp[first][1] = 0;
  for (int i = 1; i < value1.size() - 1; i++) {
    dp[first][1] += suf[i + 1] * pre[i - 1] % mod * value2[i] % mod;
    dp[first][1] %= mod;
  }
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
    color[val[i]].push_back(i);
  }
  for (int i = 1; i < n; i++) {
    int first, second;
    scanf("%d %d", &first, &second);
    v[first].push_back(second);
    v[second].push_back(first);
  }
  dfs(1, 0);
  for (int i = 1; i <= k; i++) {
    priority_queue<pair<int, int> > pq;
    for (auto it : color[i]) {
      pq.push(make_pair((dep[it]), (it)));
    }
    while (pq.size() != 1) {
      pair<int, int> hi = pq.top();
      pq.pop();
      if (val[p[hi.second]] != 0 && val[p[hi.second]] != i) {
        printf("0\n");
        return 0;
      }
      if (val[p[hi.second]] == 0) {
        val[p[hi.second]] = i;
        assert(hi.first - 1 == dep[p[hi.second]]);
        pq.push(make_pair((hi.first - 1), (p[hi.second])));
      }
    }
  }
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    if (!vis[i] && val[i] == 0) {
      dfs2(i, 0);
      ans *= dp[i][1];
      ans %= mod;
    }
  }
  printf("%lld\n", ans);
}
