#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int N = 3e5 + 5;
int n;
int a[N];
vector<int> e[N];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int sum1 = 0, sum2 = 0;
int ans;
int dp[N][3];
void INIT() {
  for (int i = 1; i <= n; i++) {
    e[i].clear();
  }
  sum1 = 0, sum2 = 0;
  ans = 0;
  memset(dp, 0, sizeof(dp));
}
void dfs(int root, int fa) {
  dp[root][a[root]]++;
  for (auto v : e[root]) {
    if (v == fa) continue;
    dfs(v, root);
    for (int j = 0; j <= 2; j++) {
      dp[root][j] += dp[v][j];
    }
    if (dp[v][1] == 0 || dp[v][2] == 0) {
      int res1 = sum1 - dp[v][1], res2 = sum2 - dp[v][2];
      if (res1 == 0 || res2 == 0) ans++;
    }
  }
}
void solve() {
  INIT();
  for (int i = 1; i <= n; i++) cin >> (a[i]);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) sum1++;
    if (a[i] == 2) sum2++;
  }
  dfs(1, 0);
  cout << (ans) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n) {
    solve();
  }
  return 0;
}
