#include <bits/stdc++.h>
using namespace std;
const int N = 300 * 1000 + 10, MOD = 998244353;
int n, k, a[N], par[N], h[N], idx[N], dp[2][N];
vector<int> adj[N], c[N];
bool flag;
int add(int a, int b) {
  a += b - MOD;
  return (a < 0 ? a + MOD : a);
}
int mul(int a, int b) { return (1ll * a * b) % MOD; }
int Pow(int a, int b) {
  return b ? (1ll * (b & 1 ? a : 1) * (Pow(mul(a, a), b >> 1))) % MOD : 1;
}
int inv(int a) { return Pow(a, MOD - 2); }
void dfs(int v = 1, int _par = 0) {
  c[a[v]].push_back(v);
  for (int u : adj[v])
    if (u ^ _par) par[u] = v, h[u] = h[v] + 1, dfs(u, v);
}
void set_color(int u, int v, int color) {
  while (u ^ v) {
    if (h[u] < h[v]) swap(u, v);
    if (a[u] && a[u] ^ color) {
      flag = true;
      return;
    }
    a[u] = color, u = par[u];
  }
  if (a[u] && a[u] ^ color) {
    flag = true;
    return;
  }
  a[u] = color;
}
void dfs_dp(int v = 1, int par = 0) {
  for (int u : adj[v])
    if (u ^ par) dfs_dp(u, v);
  int cnt = 1;
  for (int u : adj[v])
    if (u ^ par) cnt = mul(cnt, add(dp[0][u], dp[1][u]));
  dp[1][v] = (v <= k ? 0 : cnt);
  if (adj[v].size() == 0 || (adj[v].size() == 1 && adj[v][0] == par)) {
    dp[0][v] = (v <= k);
    return;
  }
  if (v <= k)
    dp[0][v] = cnt;
  else
    for (int u : adj[v])
      if (u ^ par)
        dp[0][v] = add(dp[0][v],
                       mul(dp[0][u], mul(cnt, inv(add(dp[0][u], dp[1][u])))));
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int cnt;
  cin >> n >> k, cnt = k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u);
  }
  dfs();
  for (int i = 1; i <= k; i++)
    for (int j = 0; j < (int)c[i].size() - 1; j++)
      set_color(c[i][j], c[i][j + 1], i);
  if (flag) return cout << "0\n", 0;
  for (int i = 1; i <= n; i++) idx[i] = (a[i] ? a[i] : ++cnt);
  for (int i = 1; i <= n; i++) c[i].clear();
  for (int i = 1; i <= n; i++)
    for (int u : adj[i])
      if (idx[u] ^ idx[i]) c[idx[i]].push_back(idx[u]);
  for (int i = 1; i <= n; i++) adj[i].clear();
  for (int i = 1; i <= n; i++)
    for (int u : c[i]) adj[i].push_back(u);
  dfs_dp();
  cout << dp[0][1] << '\n';
}
