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;
int n, k, t[300010], u, v, a[300010], conf[300010], tc[300010], check[300010];
long long dp[300010][2];
vector<int> edge[300010];
const long long MOD = 998244353;
long long add(long long a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
long long times(long long a, long long b) {
  a *= b;
  a %= MOD;
  return a;
}
long long fexp(long long m) {
  long long h = MOD - 2ll;
  long long r = 1ll;
  while (h > 0) {
    m %= MOD;
    if (h & 1ll) r *= m;
    m *= m;
    h >>= 1ll;
    r %= MOD;
  }
  return r;
}
void conect(int vert, int dis) {
  for (int i = 0; i < t[dis]; i++)
    if (edge[dis][i] != vert) {
      edge[vert].push_back(edge[dis][i]);
      t[vert]++;
      for (int j = 0; j < t[edge[dis][i]]; j++)
        if (edge[edge[dis][i]][j] == dis) {
          edge[edge[dis][i]][j] = vert;
          break;
        }
    }
  t[dis] = 0;
}
void super_node(int vert, int color) {
  conf[vert] = -1;
  check[vert] = a[vert];
  int h;
  if (a[vert] > 0) color = a[vert];
  for (int i = 0; i < t[vert]; i++)
    if (conf[edge[vert][i]] >= 0) {
      if (conf[edge[vert][i]] == 0) super_node(edge[vert][i], color);
      if (t[edge[vert][i]] == 1 && a[edge[vert][i]] == 0) {
        t[edge[vert][i]] = 0;
        swap(edge[vert][i], edge[vert][t[vert] - 1]);
        edge[vert].pop_back();
        t[vert]--;
        i--;
      } else if (check[edge[vert][i]] == color) {
        tc[a[edge[vert][i]]]--;
        conect(vert, edge[vert][i]);
        swap(edge[vert][i], edge[vert][t[vert] - 1]);
        edge[vert].pop_back();
        t[vert]--;
        i--;
        if (a[vert] == 0) {
          check[vert] = color;
          a[vert] = color;
          tc[color]++;
        }
      } else if (a[vert] == 0) {
        if (check[vert] == check[edge[vert][i]]) {
          color = check[vert];
          tc[a[edge[vert][i]]]--;
          conect(vert, edge[vert][i]);
          swap(edge[vert][i], edge[vert][t[vert] - 1]);
          edge[vert].pop_back();
          i--;
          t[vert]--;
          swap(edge[vert][h], edge[vert][i]);
          tc[a[edge[vert][i]]]--;
          conect(vert, edge[vert][i]);
          swap(edge[vert][i], edge[vert][t[vert] - 1]);
          edge[vert].pop_back();
          i--;
          t[vert]--;
          a[vert] = color;
          tc[color]++;
        } else if (check[vert] == 0) {
          check[vert] = check[edge[vert][i]];
          h = i;
        } else if (tc[check[edge[vert][i]]] > 1 && check[vert] != color) {
          check[vert] = check[edge[vert][i]];
          h = i;
        }
      }
    }
  conf[vert] = 1;
}
void resp(int vert) {
  conf[vert] = -1;
  if (a[vert] == 0)
    dp[vert][0] = 1;
  else
    dp[vert][1] = 1;
  for (int i = 0; i < t[vert]; i++)
    if (conf[edge[vert][i]] == 0) {
      resp(edge[vert][i]);
      dp[vert][0] =
          times(dp[vert][0], add(dp[edge[vert][i]][0], dp[edge[vert][i]][1]));
      dp[vert][1] =
          times(dp[vert][1], add(dp[edge[vert][i]][0], dp[edge[vert][i]][1]));
    }
  if (a[vert] == 0) {
    long long hf = 1;
    for (int i = 0; i < t[vert]; i++)
      if (conf[edge[vert][i]] == 1)
        hf = times(hf, add(dp[edge[vert][i]][0], dp[edge[vert][i]][1]));
    for (int i = 0; i < t[vert]; i++)
      if (conf[edge[vert][i]] == 1) {
        long long h = dp[edge[vert][i]][1];
        h = times(h, hf);
        h = times(h, fexp(add(dp[edge[vert][i]][0], dp[edge[vert][i]][1])));
        dp[vert][1] = add(dp[vert][1], h);
      }
  }
  conf[vert] = 1;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    tc[a[i]]++;
  }
  tc[0] = 0;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
    t[u]++;
    t[v]++;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] > 0) {
      super_node(i, a[i]);
      break;
    }
  for (int i = 1; i <= k; i++)
    if (tc[i] != 1) {
      printf("0\n");
      return 0;
    }
  for (int i = 1; i <= n; i++) conf[i] = 0;
  for (int i = 1; i <= n; i++)
    if (t[i] > 0) {
      resp(i);
      printf("%lld\n", dp[i][1]);
      return 0;
    }
}