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>
#pragma GCC optimize("O2")
using namespace std;
const int MAXN = 1e6 + 10;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long INF = 8e18;
const int LOG = 22;
long long pw(long long a, long long b, long long mod) {
  return (!b ? 1
             : (b & 1 ? (a * pw(a * a % mod, b / 2, mod)) % mod
                      : pw(a * a % mod, b / 2, mod)));
}
int col[MAXN], par[LOG][MAXN], H[MAXN], second[MAXN], first[MAXN], USE[MAXN],
    cnt, is_OK = 1;
int Par[MAXN], sz[MAXN], X[MAXN];
long long dp[2][MAXN];
vector<int> G[MAXN], adj[MAXN], C[MAXN], ST;
int Find(int x) { return ((x == Par[x]) ? x : Par[x] = Find(Par[x])); }
void unify(int v, int u) {
  v = Find(v), u = Find(u);
  if (v == u) return;
  if (sz[u] > sz[v]) {
    swap(u, v);
  }
  Par[u] = v;
  sz[v] += sz[u];
}
void pre(int v, int P) {
  second[v] = ++cnt;
  H[v] = H[P] + 1;
  par[0][v] = P;
  for (int T = 1; T < LOG; T++) {
    par[T][v] = par[T - 1][par[T - 1][v]];
  }
  for (auto u : G[v]) {
    if (u == P) continue;
    pre(u, v);
  }
  first[v] = cnt;
}
int k_th(int v, int del) {
  for (int T = LOG - 1; ~T; T--) {
    if (del & (1 << T)) {
      v = par[T][v];
    }
  }
  return v;
}
int LCA(int v, int u) {
  if (H[v] > H[u]) {
    swap(u, v);
  }
  int del = H[u] - H[v];
  u = k_th(u, del);
  if (u == v) {
    return v;
  }
  for (int T = LOG - 1; ~T; T--) {
    if (par[T][v] != par[T][u]) {
      u = par[T][u];
      v = par[T][v];
    }
  }
  return par[0][v];
}
void Get(int v, int Mol) {
  if (USE[v]) {
    is_OK = 0;
  }
  USE[v] = 1;
  unify(Mol, v);
  for (auto u : G[v]) {
    if (u == par[0][v]) continue;
    auto it = ST[lower_bound((ST).begin(), (ST).end(), second[u]) - ST.begin()];
    if (it <= first[u]) {
      Get(u, Mol);
    }
  }
}
void dfs(int v, int P) {
  dp[0][v] = 1;
  dp[1][v] = 0;
  for (auto u : adj[v]) {
    if (u == P) {
      continue;
    }
    dfs(u, v);
    dp[1][v] = (dp[1][v] * dp[0][u]) % MOD2;
    dp[1][v] = (dp[1][v] + dp[1][u] * dp[0][v]) % MOD2;
    dp[0][v] = (dp[0][v] * dp[0][u]) % MOD2;
  }
  if (X[v]) {
    dp[1][v] = dp[0][v];
  } else {
    dp[0][v] = (dp[0][v] + dp[1][v]) % MOD2;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    sz[i] = 1;
    Par[i] = i;
    cin >> col[i];
    if (col[i]) C[col[i]].push_back(i);
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  pre(1, 0);
  for (int i = 1; i <= k; i++) {
    ST.clear();
    ST.shrink_to_fit();
    int lca = C[i].front();
    for (auto v : C[i]) {
      ST.push_back(second[v]);
      lca = LCA(lca, v);
    }
    ST.push_back(1e9);
    sort((ST).begin(), (ST).end());
    Get(lca, lca);
    if (is_OK == 0) {
      return cout << 0, 0;
    }
  }
  int Root = 0;
  for (int i = 1; i <= n; i++) {
    int v = Find(i);
    Root = v;
    if (v == i) {
      if (sz[i] == 1 && col[i] == 0) {
        X[i] = 0;
      } else {
        X[i] = 1;
      }
    }
    for (auto u : G[i]) {
      u = Find(u);
      if (v == u) continue;
      adj[v].push_back(u);
    }
  }
  dfs(Root, 0);
  cout << dp[1][Root];
  return 0;
}