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;
long long bin[300005];
vector<int> edge[300005];
vector<int> num[300005];
int id[300005], nxt, mn[300005];
int sum[300005];
int col[300005];
int rev[300005];
int up[300005][20];
int dep[300005];
void dfs(int v, int u) {
  rev[nxt] = v;
  id[v] = nxt++;
  if (col[v]) sum[v] = 1;
  up[v][0] = u;
  if (u == -1)
    dep[v] = 0;
  else
    dep[v] = dep[u] + 1;
  for (int i = 0; i < edge[v].size(); i++) {
    if (edge[v][i] == u) continue;
    dfs(edge[v][i], v);
    sum[v] += sum[edge[v][i]];
  }
}
bool fb[300005];
set<int> ss[300005];
bool cmp(const int& a, const int& b) { return id[a] < id[b]; }
int lca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  int D = dep[b] - dep[a];
  for (int i = 19; i >= 0; i--) {
    if (D >= (1 << i)) {
      D -= (1 << i);
      b = up[b][i];
    }
  }
  if (a == b) return a;
  for (int i = 19; i >= 0; i--) {
    if (up[a][i] != up[b][i]) {
      a = up[a][i];
      b = up[b][i];
    }
  }
  return up[a][0];
}
vector<int> G[600005];
long long dp[600005][2];
void calc(int v, int u) {
  bool is_leaf = true;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] == u) continue;
    is_leaf = 0;
    calc(G[v][i], v);
  }
  if (is_leaf) {
    if (v > 300002) {
      dp[v][1] = 1;
    } else {
      dp[v][0] = 1;
    }
    return;
  } else if (v > 300002) {
    dp[v][1] = 1;
    for (int i = 0; i < G[v].size(); i++) {
      if (G[v][i] == u) continue;
      dp[v][1] *= (dp[G[v][i]][0] + dp[G[v][i]][1]) % 998244353;
      dp[v][1] %= 998244353;
    }
  } else {
    dp[v][0] = 1;
    long long gg[2][2] = {};
    gg[0][0] = 1;
    gg[0][1] = 0;
    int cur = 0, nxt = 1;
    for (int i = 0; i < G[v].size(); i++) {
      if (G[v][i] == u) continue;
      for (int w = 0; w < 2; w++) gg[nxt][w] = 0;
      dp[v][0] *= (dp[G[v][i]][0] + dp[G[v][i]][1]) % 998244353;
      dp[v][0] %= 998244353;
      gg[nxt][0] =
          (gg[cur][0] * ((dp[G[v][i]][0] + dp[G[v][i]][1]) % 998244353)) %
          998244353;
      gg[nxt][1] =
          (gg[cur][1] * ((dp[G[v][i]][0] + dp[G[v][i]][1]) % 998244353)) %
          998244353;
      gg[nxt][1] +=
          (gg[cur][0] * ((0 + dp[G[v][i]][1]) % 998244353)) % 998244353;
      gg[nxt][1] %= 998244353;
      swap(cur, nxt);
    }
    dp[v][1] = gg[cur][1];
  }
}
int main() {
  scanf("%d%d", &n, &k);
  bin[0] = 1;
  for (int i = 1; i <= 300000; i++) bin[i] = bin[i - 1] * 2LL % 998244353;
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    col[i] = a;
    if (a) {
      num[a].push_back(i);
    }
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  int root = num[1][0];
  dfs(root, -1);
  fb[root] = 1;
  long long ans = 1;
  for (int j = 0; j < 19; j++) {
    for (int i = 1; i <= n; i++) {
      if (up[i][j] == -1)
        up[i][j + 1] = -1;
      else
        up[i][j + 1] = up[up[i][j]][j];
    }
  }
  for (int i = 1; i <= k; i++) {
    sort(num[i].begin(), num[i].end(), cmp);
    mn[i] = num[i][0];
    for (int j = 1; j < num[i].size(); j++) {
      int L = lca(num[i][j - 1], num[i][j]);
      if (id[mn[i]] > id[L]) {
        mn[i] = L;
      }
    }
    for (int j = 0; j < num[i].size(); j++) {
      int cur = num[i][j];
      while (1) {
        if (ss[cur].find(i) != ss[cur].end()) break;
        ss[cur].insert(i);
        if (ss[cur].size() >= 2) {
          puts("0");
          return 0;
        }
        if (cur == mn[i]) break;
        cur = up[cur][0];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (up[i][0] == -1) continue;
    int j = up[i][0];
    int ii = i, jj = j;
    if (ss[j].size()) j = *ss[j].begin() + 300002;
    if (ss[i].size()) i = *ss[i].begin() + 300002;
    if (j == i) {
      i = ii;
      continue;
    }
    G[j].push_back(i);
    i = ii;
  }
  calc(300003, -1);
  cout << (dp[300003][1] % 998244353 + 998244353) % 998244353 << endl;
}