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;
int c[300010], lc[300010], now[300010];
int fa[30][300010], dep[300010], g[300010];
long long f[300010][2];
bool flag;
vector<int> E[300010], Q1[300010], Q2[300010];
vector<long long> pre, suf;
inline void insert(int a, int b) {
  E[a].push_back(b);
  E[b].push_back(a);
}
int lca(int a, int b) {
  int k;
  if (dep[a] != dep[b]) {
    if (dep[a] < dep[b]) swap(a, b);
    k = 0;
    while (dep[fa[k][a]] > dep[b]) k++;
    while (k >= 0) {
      if (dep[fa[k][a]] > dep[b]) a = fa[k][a];
      k--;
    }
    a = fa[0][a];
  }
  if (a == b) return a;
  k = 0;
  while (fa[k][a] != fa[k][b]) k++;
  while (k >= 0) {
    if (fa[k][a] != fa[k][b]) {
      a = fa[k][a];
      b = fa[k][b];
    }
    k--;
  }
  return fa[0][a];
}
void dfs1(int x) {
  for (int i = 0; i < E[x].size(); i++)
    if (fa[0][x] != E[x][i]) {
      fa[0][E[x][i]] = x;
      dep[E[x][i]] = dep[x] + 1;
      dfs1(E[x][i]);
    }
}
void dfs2(int x) {
  if (c[x]) {
    if (now[c[x]])
      g[x] = c[x];
    else
      g[x] = -1;
  }
  for (int i = 0; i < E[x].size(); i++)
    if (fa[0][x] != E[x][i]) {
      now[c[x]]++;
      dfs2(E[x][i]);
      if (flag) return;
      now[c[x]]--;
      if (g[E[x][i]] && !g[x]) g[x] = -1;
      if (g[E[x][i]] > 0 && now[g[E[x][i]]]) {
        if (c[x] && g[E[x][i]] != c[x]) {
          flag = 1;
          return;
        }
        if (!g[x] || g[x] == -1) {
          g[x] = g[E[x][i]];
          c[x] = g[x];
          continue;
        }
        if (g[x] != g[E[x][i]]) {
          flag = 1;
          return;
        }
      }
    }
}
void dfs3(int x) {
  int a;
  long long s;
  for (int i = 0; i < E[x].size(); i++)
    if (fa[0][x] != E[x][i]) {
      dfs3(E[x][i]);
      if (g[E[x][i]] > 0) Q1[x].push_back(E[x][i]);
      if (g[E[x][i]] == -1) Q2[x].push_back(E[x][i]);
    }
  if (Q1[x].empty() && Q2[x].empty()) {
    if (c[x]) {
      f[x][0] = 0;
      f[x][1] = 1;
    } else {
      f[x][0] = 1;
      f[x][1] = 0;
    }
    return;
  }
  if (!c[x] && Q1[x].empty()) {
    f[x][0] = s = 1;
    a = Q2[x].size();
    for (int i = 0; i < a; i++) {
      f[x][0] = f[x][0] * (f[Q2[x][i]][0] + f[Q2[x][i]][1]) % 998244353;
      pre.push_back(f[x][0]);
    }
    for (int i = a - 1; i >= 0; i--) {
      s = s * (f[Q2[x][i]][0] + f[Q2[x][i]][1]) % 998244353;
      suf.push_back(s);
    }
    reverse(suf.begin(), suf.end());
    for (int i = 0; i < a; i++) {
      s = f[Q2[x][i]][1];
      if (i) s = s * pre[i - 1] % 998244353;
      if (i < a - 1) s = s * suf[i + 1] % 998244353;
      f[x][1] += s;
      if (f[x][1] >= 998244353) f[x][1] %= 998244353;
    }
    pre.clear();
    suf.clear();
  } else {
    f[x][0] = 0;
    f[x][1] = 1;
    for (int i = 0; i < Q2[x].size(); i++)
      f[x][1] = f[x][1] * (f[Q2[x][i]][0] + f[Q2[x][i]][1]) % 998244353;
    for (int i = 0; i < Q1[x].size(); i++)
      f[x][1] = f[x][1] * f[Q1[x][i]][1] % 998244353;
  }
}
int main() {
  int a, b;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    insert(a, b);
  }
  dfs1(1);
  for (int i = 1; i <= 20; i++)
    for (int j = 1; j <= n; j++) fa[i][j] = fa[i - 1][fa[i - 1][j]];
  for (int i = 1; i <= n; i++)
    if (c[i]) {
      if (!lc[c[i]]) {
        lc[c[i]] = i;
        continue;
      }
      lc[c[i]] = lca(lc[c[i]], i);
      if (!c[lc[c[i]]]) {
        c[lc[c[i]]] = c[i];
        continue;
      }
      if (c[lc[c[i]]] != c[i]) {
        puts("0");
        return 0;
      }
    }
  dfs2(1);
  if (flag) {
    puts("0");
    return 0;
  }
  dfs3(1);
  cout << f[1][1] << endl;
  return 0;
}