#include <bits/stdc++.h>
using namespace std;
const int N = 3000 * 100 + 5, Mod = 998244353;
int n, k, par[N], c[N], h[N], dp[2][N], ind[N];
vector<int> adj[N], col[N];
bool is;
int mul(int a, int b) {
  long long c = (1ll * a * b) % Mod;
  return c;
}
int Pow(int a, int b) {
  int val = a, ans = 1;
  while (b) {
    if (b % 2) ans = mul(ans, val);
    val = mul(val, val), b /= 2;
  }
  return ans;
}
int inv(int a) { return Pow(a, Mod - 2); }
int add(int a, int b) {
  a += b - Mod;
  return (a < 0 ? a + Mod : a);
}
void dfs(int v, int x) {
  par[v] = x, col[c[v]].push_back(v);
  for (auto u : adj[v])
    if (x != u) h[u] = h[v] + 1, dfs(u, v);
}
void setColor(int v, int u, int color) {
  while (v != u) {
    if (h[v] < h[u]) swap(v, u);
    if (c[v] && c[v] != color) {
      is = true;
      return;
    }
    c[v] = color;
    v = par[v];
  }
  if (c[v] && c[v] != color) {
    is = true;
    return;
  }
  c[v] = color;
}
void dfsDp(int v = 1, int p = 0) {
  for (int u : col[v])
    if (u ^ p) dfsDp(u, v);
  int cnt = 1;
  for (int u : col[v])
    if (u ^ p) cnt = mul(cnt, add(dp[0][u], dp[1][u]));
  dp[1][v] = (v <= k ? 0 : cnt);
  if (col[v].size() == 0 || (col[v].size() == 1 && col[v][0] == p)) {
    dp[0][v] = (v <= k);
    return;
  }
  if (v <= k)
    dp[0][v] = cnt;
  else
    for (int u : col[v])
      if (u ^ p)
        dp[0][v] = add(dp[0][v],
                       mul(dp[0][u], mul(cnt, inv(add(dp[0][u], dp[1][u])))));
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 2, v, u; i <= n; i++) {
    cin >> v >> u;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  dfs(1, 0);
  for (int i = 1; i <= k; i++)
    for (int j = 1; j < col[i].size(); j++)
      setColor(col[i][j - 1], col[i][j], i);
  if (is) return cout << 0 << endl, 0;
  int cnt = k + 1;
  for (int i = 1; i <= n; i++) {
    if (c[i] == 0)
      ind[i] = cnt++;
    else
      ind[i] = c[i];
  }
  for (int i = 1; i <= n; i++) col[i].clear();
  for (int v = 1; v <= n; v++)
    for (auto u : adj[v])
      if (ind[v] != ind[u]) col[ind[v]].push_back(ind[u]);
  dfsDp(1, 0);
  cout << dp[0][1] << endl;
}
