#include <bits/stdc++.h>
using namespace std;
vector<int> v[300001];
long long has[300001][3], ar[300001], ct, ct2;
void dfs(int i, int p) {
  has[i][ar[i]] = 1;
  if (ar[i] == 1)
    ++ct;
  else if (ar[i] == 2)
    ++ct2;
  for (int j = 0; j < v[i].size(); ++j) {
    if (v[i][j] == p) continue;
    dfs(v[i][j], i);
    has[i][1] += has[v[i][j]][1];
    has[i][2] += has[v[i][j]][2];
  }
}
int ans;
void dfs2(int i, int p) {
  for (int j = 0; j < v[i].size(); ++j) {
    if (v[i][j] == p) continue;
    dfs2(v[i][j], i);
    if (has[v[i][j]][1] == 0 && (ct2 - has[v[i][j]][2]) == 0) {
      ++ans;
    } else if (has[v[i][j]][2] == 0 && (ct - has[v[i][j]][1]) == 0) {
      ++ans;
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  int T;
  T = 1;
  while (T--) {
    int n, i, j, a, b;
    cin >> n;
    for (i = 1; i <= n; ++i) cin >> ar[i];
    for (i = 1; i <= n - 1; ++i) {
      cin >> a >> b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    dfs(1, -1);
    dfs2(1, -1);
    cout << ans << endl;
  }
  return 0;
}
