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 MXN = 3e5 + 10;
const long long Mod = 998244353;
const long long LOG = 20;
long long n, k;
long long A[MXN], has[MXN], dp[2][MXN];
long long Par[MXN], Sz[MXN], R[2][MXN];
long long Jad[LOG][MXN], dis[MXN];
vector<long long> adj[MXN], G[MXN], Col[MXN];
vector<pair<long long, long long>> E;
inline void mkay(long long& x) {
  if (x >= Mod) x -= Mod;
}
long long power(long long a, long long b) {
  return (!b ? 1 : power(a * a % Mod, b / 2) * (b & 1LL ? a : 1) % Mod);
}
long long Find(long long x) {
  return (x == Par[x] ? x : Par[x] = Find(Par[x]));
}
void Union(long long x, long long y) {
  x = Find(x), y = Find(y);
  if (x == y) return;
  if (Sz[x] < Sz[y]) swap(x, y);
  Sz[x] += Sz[y], Par[y] = x;
  if (R[0][x] == 0)
    R[0][x] = R[0][y], R[1][x] = R[1][y];
  else if (R[0][y] > 0) {
    R[0][x] = min(R[0][x], R[0][y]);
    R[1][x] = max(R[1][x], R[1][y]);
  }
}
void prep(long long u, long long par) {
  Jad[0][u] = par;
  if (A[u]) Col[A[u]].push_back(u);
  for (int i = 1; i < LOG; i++) {
    Jad[i][u] = Jad[i - 1][Jad[i - 1][u]];
  }
  for (auto v : adj[u]) {
    if (v != par) dis[v] = dis[u] + 1, prep(v, u);
  }
}
long long K_Jad(long long u, long long k) {
  for (int i = 0; i < LOG; i++) {
    if ((k >> i) & 1LL) u = Jad[i][u];
  }
  return u;
}
long long LCA(long long u, long long v) {
  if (dis[v] < dis[u]) swap(u, v);
  v = K_Jad(v, dis[v] - dis[u]);
  if (u == v) return u;
  for (int i = LOG - 1; ~i; i--) {
    if (Jad[i][u] != Jad[i][v]) u = Jad[i][u], v = Jad[i][v];
  }
  return Jad[0][u];
}
void flood(long long u, long long par) {
  for (auto v : adj[u]) {
    if (v == par) continue;
    flood(v, u), has[u] += has[v];
    if (has[v]) Union(u, v);
  }
}
void DFS(long long u, long long par) {
  dp[0][u] = 1;
  for (auto v : G[u]) {
    if (v == par) continue;
    DFS(v, u);
    dp[0][u] = dp[0][u] * ((dp[0][v] + dp[1][v]) % Mod) % Mod;
  }
  for (auto v : G[u]) {
    if (v == par) continue;
    long long other =
        dp[0][u] * power((dp[0][v] + dp[1][v]) % Mod, Mod - 2) % Mod;
    dp[1][u] += other * dp[1][v] % Mod;
    mkay(dp[1][u]);
  }
  if (R[0][u]) dp[1][u] = dp[0][u], dp[0][u] = 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  iota(Par + 1, Par + n + 1, 1), fill(Sz + 1, Sz + n + 1, 1);
  for (int i = 1; i <= n; i++) cin >> A[i], R[0][i] = R[1][i] = A[i];
  for (int i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v), adj[v].push_back(u);
    E.push_back({u, v});
  }
  prep(1, 0);
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j < Col[i].size(); j++) {
      long long u = Col[i][j - 1], v = Col[i][j];
      has[u]++, has[v]++, has[LCA(u, v)] -= 2;
    }
  }
  flood(1, 0);
  for (int i = 1; i <= n; i++) {
    if (i == Par[i]) {
      if (R[0][i] != R[1][i]) return cout << 0, 0;
    }
  }
  for (auto e : E) {
    long long u, v;
    tie(u, v) = e;
    u = Find(u), v = Find(v);
    if (u == v) continue;
    G[u].push_back(v), G[v].push_back(u);
  }
  DFS(Find(1), 0);
  cout << dp[1][Find(1)] << '\n';
  return 0;
}