Problem: You are given an undirected tree of n vertices. 

Some vertices are colored blue, some are colored red and some are uncolored. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex.

You choose an edge and remove it from the tree. Tree falls apart into two connected components. Let's call an edge nice if neither of the resulting components contain vertices of both red and blue colors.

How many nice edges are there in the given tree?

Input

The first line contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of vertices in the tree.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2) — the colors of the vertices. a_i = 1 means that vertex i is colored red, a_i = 2 means that vertex i is colored blue and a_i = 0 means that vertex i is uncolored.

The i-th of the next n - 1 lines contains two integers v_i and u_i (1 ≤ v_i, u_i ≤ n, v_i ≠ u_i) — the edges of the tree. It is guaranteed that the given edges form a tree. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex.

Output

Print a single integer — the number of nice edges in the given tree.

Examples

Input


5
2 0 0 1 2
1 2
2 3
2 4
2 5


Output


1


Input


5
1 0 0 0 2
1 2
2 3
3 4
4 5


Output


4


Input


3
1 1 2
2 3
1 3


Output


0

Note

Here is the tree from the first example:

<image>

The only nice edge is edge (2, 4). Removing it makes the tree fall apart into components \{4\} and \{1, 2, 3, 5\}. The first component only includes a red vertex and the second component includes blue vertices and uncolored vertices.

Here is the tree from the second example:

<image>

Every edge is nice in it.

Here is the tree from the third example:

<image>

Edge (1, 3) splits the into components \{1\} and \{3, 2\}, the latter one includes both red and blue vertex, thus the edge isn't nice. Edge (2, 3) splits the into components \{1, 3\} and \{2\}, the former one includes both red and blue vertex, thus the edge also isn't nice. So the answer is 0.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
namespace IO {
const int IN_LEN = 1 << 18 | 1;
static char buf[IN_LEN], *s, *t;
inline int Getchar(void) {
  return s == t && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)),
         s == t ? -1 : *s++;
}
template <class T>
inline void read(T& x) {
  static int c, f;
  for (c = Getchar(), f = 0; c < '0' || c > '9'; c = Getchar())
    if (c == '-') f = 1;
  for (x = 0; c <= '9' && c >= '0'; c = Getchar()) x = x * 10 + c - 48;
  x = f ? -x : x;
}
}  // namespace IO
using IO::read;
const int MAXN = 3e5 + 1, mod = 998244353;
int n, k, mark[MAXN], num[MAXN], cot[MAXN];
struct Edge {
  int u, v;
} dat[MAXN];
namespace myMath {
void exgcd(int a, int b, long long& x, long long& y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, x, y);
  long long tx = x;
  x = y, y = tx - a / b * y;
}
inline int inv(int num) {
  static long long x, y;
  exgcd(num, mod, x, y);
  if ((x %= mod) < 0) x += mod;
  return x;
}
inline int plus(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
}  // namespace myMath
using myMath::inv;
using myMath::plus;
namespace Union {
int f[MAXN];
int find(int x) { return x == f[x] ? f[x] : f[x] = find(f[x]); }
}  // namespace Union
namespace DP {
int f[MAXN][2], head[MAXN], cnt, ext[MAXN];
struct EE {
  int next, to;
} edge[MAXN << 1];
inline void addedge(int f, int t) {
  edge[++cnt] = (EE){head[f], t};
  head[f] = cnt;
}
int dfs(int u, int fa) {
  int res = (u <= k);
  for (int i = head[u]; i; i = edge[i].next)
    if (edge[i].to != fa) res += dfs(edge[i].to, u);
  if (res > 0) ext[u] = 1;
  return res;
}
void dp(int u, int fa) {
  if (u <= k) {
    f[u][0] = 0, f[u][1] = 1;
    for (int i = head[u], v; i; i = edge[i].next)
      if ((v = edge[i].to) != fa && ext[v]) {
        dp(v, u);
        f[u][1] = 1LL * f[u][1] * (f[v][0] + f[v][1]) % mod;
      }
  } else {
    f[u][0] = 1, f[u][1] = 0;
    int tmp = 1;
    for (int i = head[u], v; i; i = edge[i].next)
      if ((v = edge[i].to) != fa && ext[v]) {
        dp(v, u);
        f[u][0] = 1LL * f[u][0] * (1LL * f[v][1] + f[v][0]) % mod;
        tmp = 1LL * tmp * (1LL * f[v][0] + f[v][1]) % mod;
      }
    for (int i = head[u], v; i; i = edge[i].next)
      if ((v = edge[i].to) != fa && ext[v]) {
        f[u][1] = plus(f[u][1],
                       1LL * (1LL * tmp * inv(plus(f[v][0], f[v][1])) % mod) *
                           f[v][1] % mod);
      }
  }
  return;
}
int solve(void) {
  dfs(1, 0);
  dp(1, 0);
  return f[1][1];
}
}  // namespace DP
namespace Prework {
int lca[MAXN], head[MAXN], cnt, fir[MAXN];
struct EE {
  int next, to;
} edge[MAXN << 1];
inline void addedge(int f, int t) {
  edge[++cnt] = (EE){head[f], t};
  head[f] = cnt;
}
void dfs1(int u, int fa) {
  if (mark[u]) {
    if (!fir[mark[u]]) fir[mark[u]] = u;
    if (--cot[mark[u]] == 0) lca[mark[u]] = Union::find(fir[mark[u]]);
  }
  for (int i = head[u]; i; i = edge[i].next)
    if (edge[i].to != fa) dfs1(edge[i].to, u);
  Union::f[u] = fa;
}
int dfs2(int u, int fa) {
  int res = mark[u], tmp;
  if (mark[u]) ++cot[mark[u]];
  for (int i = head[u]; i; i = edge[i].next)
    if (edge[i].to != fa) {
      tmp = dfs2(edge[i].to, u);
      if (tmp == -1) return -1;
      if (tmp && res && tmp != res) return -1;
      if (!res) res = tmp;
    }
  if (mark[u])
    if (--cot[mark[u]] == 0) return 0;
  return mark[u] = res;
}
bool pre(void) {
  for (int i = 1; i <= n; ++i) Union::f[i] = i;
  dfs1(1, 0);
  for (int i = 1; i <= k; ++i)
    if (mark[lca[i]] && mark[lca[i]] != i)
      return false;
    else
      mark[lca[i]] = i;
  if (dfs2(1, 0) == -1) return false;
  int tmp = k;
  for (int i = 1; i <= n; ++i)
    if (mark[i])
      num[i] = mark[i];
    else
      num[i] = ++tmp;
  for (int i = 1; i < n; ++i)
    if (num[dat[i].u] != num[dat[i].v]) {
      DP::addedge(num[dat[i].u], num[dat[i].v]),
          DP::addedge(num[dat[i].v], num[dat[i].u]);
    }
  return true;
}
}  // namespace Prework
int main(void) {
  read(n), read(k);
  for (int i = 1; i <= n; ++i) {
    read(mark[i]);
    if (mark[i]) ++cot[mark[i]];
  }
  for (int i = 1; i < n; ++i) {
    read(dat[i].u), read(dat[i].v);
    Prework::addedge(dat[i].u, dat[i].v);
    Prework::addedge(dat[i].v, dat[i].u);
  }
  if (!Prework::pre()) {
    puts("0");
    return 0;
  }
  printf("%d", DP::solve());
  return 0;
}