#include <bits/stdc++.h>
using namespace std;
const int M = 300005, mod = 998244353;
int n, k, l[M], c[M];
long long ans = 1, dp[M][2];
vector<int> adj[M];
bitset<M> bs;
struct DSU {
  int p[M], lvl[M], to[M];
  DSU() { iota(p, p + M, 0); }
  int parent(int a) { return a == p[a] ? a : p[a] = parent(p[a]); }
  int join(int a, int b) {
    a = parent(a), b = parent(b);
    if (lvl[a] > lvl[b]) swap(a, b);
    p[b] = a;
    if (c[b]) c[a] = c[b];
  }
} ds;
void no() {
  cout << 0 << '\n';
  exit(0);
}
void pre(int u) {
  for (int v : adj[u])
    if (v != ds.to[u]) {
      ds.to[v] = u;
      ds.lvl[v] = ds.lvl[u] + 1;
      pre(v);
    }
}
void join(int a, int b) {
  while (1) {
    a = ds.parent(a), b = ds.parent(b);
    if (a == b) break;
    if (ds.lvl[a] > ds.lvl[b]) swap(a, b);
    if (c[b] && c[ds.to[b]] && c[b] != c[ds.to[b]]) no();
    ds.join(b, ds.to[b]);
  }
}
long long bpow(long long b, int p) {
  long long ans = 1;
  while (p) {
    if (p & 1) (ans *= b) %= mod;
    (b *= b) %= mod;
    p /= 2;
  }
  return ans;
}
long long dfs(int u, int p, int f) {
  bs[u] = 1;
  if (c[u]) return 1;
  if (dp[u][f] != -1) return dp[u][f];
  long long x = 1, y = 0;
  for (int v : adj[u])
    if (v != p) (x *= dfs(v, u, 0)) %= mod;
  for (int v : adj[u])
    if (v != p)
      (y += x * bpow(dfs(v, u, 0), mod - 2) % mod * dfs(v, u, 1)) %= mod;
  if (f) return dp[u][f] = y;
  return dp[u][f] = (x + y) % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  ds.to[1] = 1, ds.lvl[1] = 0;
  pre(1);
  for (int i = 1; i <= n; i++) {
    if (!c[i]) continue;
    if (l[c[i]]) join(l[c[i]], i);
    l[c[i]] = i;
  }
  for (int i = 1; i <= n; i++) c[i] = c[ds.parent(i)];
  for (int i = 1; i <= n; i++)
    if (!c[i] && !bs[i]) (ans *= dfs(i, i, 1)) %= mod;
  cout << ans << '\n';
  return 0;
}
