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>
using namespace std;
namespace io {
const int L = (1 << 20) + 1;
char buf[L], *S, *T, c;
char getchar() {
  if (__builtin_expect(S == T, 0)) {
    T = (S = buf) + fread(buf, 1, L, stdin);
    return (S == T ? EOF : *S++);
  }
  return *S++;
}
int inp() {
  int x = 0, f = 1;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return x * f;
}
unsigned inpu() {
  unsigned x = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    ;
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return x;
}
long long inp_ll() {
  long long x = 0;
  int f = 1;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return x * f;
}
char B[25], *outs = B + 20, *outr = B + 20;
template <class T>
inline void print(register T a, register char x = 0) {
  if (x) *--outs = x, x = 0;
  if (!a)
    *--outs = '0';
  else
    while (a) *--outs = (a % 10) + 48, a /= 10;
  if (x) *--outs = x;
  fwrite(outs, outr - outs, 1, stdout);
  outs = outr;
}
};  // namespace io
using io ::inp;
using io ::inp_ll;
using io ::inpu;
using io ::print;
using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
long long power(long long a, long long b, long long p) {
  if (!b) return 1;
  long long t = power(a, b / 2, p);
  t = t * t % p;
  if (b & 1) t = t * a % p;
  return t;
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long px, py;
  long long d = exgcd(b, a % b, px, py);
  x = py;
  y = px - a / b * py;
  return d;
}
template <class T>
inline void freshmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
inline void freshmax(T &a, const T &b) {
  if (a < b) a = b;
}
const int MAXN = 300010;
const int MOD = 998244353;
const f80 MI = f80(1) / MOD;
const int INF = 1000000000;
int n, k;
vector<int> v[MAXN];
int a[MAXN], c[MAXN], to[MAXN];
int pre[MAXN];
int head, tail, Q[MAXN];
int u[MAXN];
vector<int> w[MAXN];
bool bfs() {
  Q[head = tail = 1] = u[1] = 1;
  while (head <= tail) {
    int x = Q[head++];
    for (auto y : v[x])
      if (!u[y]) {
        u[Q[++tail] = y] = 1;
        pre[y] = x;
      }
  }
  for (int k = n; k >= 1; --k) {
    int x = Q[k];
    if (!a[x]) continue;
    if (c[a[x]] == 1) {
      to[a[x]] = x;
      continue;
    }
    if (!a[pre[x]])
      a[pre[x]] = a[x];
    else if (a[pre[x]] == a[x])
      c[a[x]]--;
    else
      return false;
  }
  for (int x = 2; x <= n; ++x)
    if (!a[x] || a[x] != a[pre[x]]) {
      int y = pre[x];
      w[a[y] ? to[a[y]] : y].push_back(x);
    }
  return true;
}
int prod[MAXN];
int f[MAXN][2];
void dfs(int x) {
  for (auto y : w[x]) dfs(y);
  prod[w[x].size()] = 1;
  for (int i = w[x].size() - 1; i >= 0; --i) {
    int y = w[x][i];
    prod[i] = (long long)prod[i + 1] * (f[y][0] + f[y][1]) % MOD;
  }
  if (a[x] == 0) {
    f[x][0] = prod[0];
    f[x][1] = 0;
    for (int i = 0, tmp = 1; i < w[x].size(); ++i) {
      int y = w[x][i];
      f[x][1] = (f[x][1] + (long long)tmp * f[y][1] % MOD * prod[i + 1]) % MOD;
      tmp = (long long)tmp * (f[y][0] + f[y][1]) % MOD;
    }
  } else {
    f[x][0] = 0;
    f[x][1] = prod[0];
  }
}
int main() {
  n = inp();
  k = inp();
  for (int i = 1; i <= n; ++i) {
    a[i] = inp();
    c[a[i]]++;
  }
  for (int i = 1; i < n; ++i) {
    int x = inp();
    int y = inp();
    v[x].push_back(y);
    v[y].push_back(x);
  }
  if (!bfs()) {
    puts("0");
    return 0;
  }
  dfs(1);
  cout << f[1][1] << endl;
  return 0;
}