#include <bits/stdc++.h>
using namespace std;
int a[300005];
vector<int> con[300005];
int c[300005][3];
void dfs(int x, int fro) {
  int i, j, k;
  for (i = 0; i < con[x].size(); i++) {
    if (con[x][i] == fro) {
      continue;
    } else {
      dfs(con[x][i], x);
      for (j = 0; j < 3; j++) {
        c[x][j] += c[con[x][i]][j];
      }
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int i, j, k;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    c[i][a[i]]++;
  }
  for (i = 1; i < n; i++) {
    scanf("%d %d", &j, &k);
    con[j].push_back(k);
    con[k].push_back(j);
  }
  int ans = 0;
  dfs(1, -1);
  for (i = 2; i <= n; i++) {
    if ((c[i][1] == 0 || c[i][2] == 0) &&
        ((c[1][1] == c[i][1]) || (c[1][2] == c[i][2]))) {
      ans++;
    }
  }
  printf("%d", ans);
  return 0;
}
