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;
const long long int MOD = 998244353;
const long long BIG = 1446803456761533460LL;
const int Big = 336860180;
const long long int INF = LONG_LONG_MAX;
const long long int adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long int adj8[8][2] = {{0, 1},   {0, -1}, {1, 0},  {-1, 0},
                                  {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int powMod(long long int a, long long int b) {
  long long int n = 1;
  long long int p = a;
  while (b > 0) {
    if (b % 2 == 1) {
      n *= p;
      n %= MOD;
    }
    p *= p;
    p %= MOD;
    b /= 2;
  }
  return n;
}
long long int modularInverse(long long int a) { return powMod(a, MOD - 2); }
stringstream sss;
const long long int maxn = 300010;
const long long int maxnlg = 20;
long long int n, k;
vector<long long int> g[maxn];
vector<long long int> cols[maxn];
long long int st[maxn], ft[maxn];
long long int H[maxn], pars[maxnlg][maxn];
long long int val[maxn];
long long int rt[maxn];
vector<long long int> gg[maxn];
long long int colrt[maxn];
long long int blk[maxn];
long long int dp[maxn][2];
long long int plt[maxn];
long long int tim = 0;
void dfs_lca(long long int x, long long int par) {
  st[x] = tim++;
  pars[0][x] = par;
  for (long long int i = (0); i < (maxnlg - 1); ++i) {
    pars[i + 1][x] = pars[i][pars[i][x]];
  }
  for (auto y : g[x]) {
    if (y != par) {
      H[y] = H[x] + 1;
      dfs_lca(y, x);
    }
  }
  ft[x] = tim;
}
long long int LCA(long long int a, long long int b) {
  if (st[a] > st[b]) swap(a, b);
  if (ft[a] >= ft[b]) return a;
  for (long long int i = (maxnlg)-1; i >= (0); --i) {
    if (ft[pars[i][a]] < ft[b]) {
      a = pars[i][a];
    }
  }
  return pars[0][a];
}
long long int root(long long int x) {
  return rt[x] == x ? x : rt[x] = root(rt[x]);
}
void dfs_merge(long long int x, long long int par) {
  for (auto y : g[x]) {
    if (y == par) continue;
    dfs_merge(y, x);
    val[x] += val[y];
  }
  if (val[x]) {
    rt[root(x)] = root(par);
  }
}
void dfs_dp(long long int x, long long int par) {
  for (auto y : gg[x]) {
    if (y == par) continue;
    dfs_dp(y, x);
  }
  long long int nn = gg[x].size();
  plt[0] = 1;
  for (long long int i = (0); i < (nn); ++i) {
    long long int v = gg[x][i];
    if (v == par) {
      plt[i + 1] = plt[i];
    } else {
      plt[i + 1] = plt[i] * (dp[v][0] + dp[v][1]) % MOD;
    }
  }
  if (blk[x]) {
    dp[x][0] = 0;
    dp[x][1] = plt[nn];
  } else {
    dp[x][0] = plt[nn];
    long long int prt = 1;
    for (long long int i = (nn)-1; i >= (0); --i) {
      long long int v = gg[x][i];
      if (v != par) {
        dp[x][1] = (dp[x][1] + (plt[i] * prt % MOD * dp[v][1])) % MOD;
        prt = (prt * (dp[v][0] + dp[v][1])) % MOD;
      }
    }
  }
}
void MAIN() {
  cin >> n >> k;
  for (long long int i = (0); i < (n); ++i) {
    long long int x;
    cin >> x;
    if (x != 0) {
      --x;
      cols[x].push_back(i);
    }
  }
  for (long long int i = (0); i < (n - 1); ++i) {
    long long int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs_lca(0, 0);
  for (long long int i = (0); i < (k); ++i) {
    long long int a = cols[i][0];
    long long int b = cols[i][0];
    for (auto u : cols[i]) {
      val[u]++;
      if (st[u] < st[a]) a = u;
      if (st[u] > st[b]) b = u;
    }
    long long int c = LCA(a, b);
    val[c] -= cols[i].size();
  }
  iota(rt, rt + n, 0);
  dfs_merge(0, 0);
  for (long long int i = (0); i < (k); ++i) {
    for (auto u : cols[i]) {
      long long int colr = root(u);
      if (colrt[colr] && colrt[colr] != i + 1) {
        cout << (0) << '\n';
        return;
      }
      colrt[colr] = i + 1;
      blk[colr] = 1;
    }
  }
  for (long long int x = (0); x < (n); ++x) {
    for (auto y : g[x]) {
      long long int rx = root(x);
      long long int ry = root(y);
      if (rx != ry) {
        gg[rx].push_back(ry);
      }
    }
  }
  dfs_dp(root(0), -1);
  cout << (dp[root(0)][1]) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
6 2
0 2 0 0 0 1
1 2
2 3
3 4
4 5
4 6
7 3
0 1 0 2 2 3 0
1 3
1 4
1 5
2 7
3 6
4 7
    )";
  MAIN();
  return 0;
}