#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int n;
int ans;
int a[maxn];
int b[maxn][3];
int c[3];
vector<int> vec[maxn];
void dfs(int now, int pre) {
  b[now][a[now]]++;
  for (auto i : vec[now]) {
    if (i != pre) {
      dfs(i, now);
      b[now][1] += b[i][1];
      b[now][2] += b[i][2];
    }
  }
  if (b[now][1] && b[now][2]) return;
  if (b[now][1] == c[1] || b[now][2] == c[2]) ans++;
}
int main() {
  cin >> n;
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c[a[i]]++;
  }
  for (int i = 1, v, u; i < n; i++) {
    cin >> v >> u;
    vec[v].push_back(u);
    vec[u].push_back(v);
  }
  memset(b, 0, sizeof(b));
  ans = 0;
  dfs(1, 0);
  cout << ans << endl;
  return 0;
}
