#include <bits/stdc++.h>
using namespace std;
const int MX = 300007;
int N, C[MX], F[MX], R[MX], B[MX], Rs, Bs, Ans;
vector<int> V[MX];
void dfs(int x, int f) {
  F[x] = f;
  R[x] = (C[x] == 1);
  B[x] = (C[x] == 2);
  int sz = V[x].size();
  for (int i = (0); i < (sz); i++)
    if (V[x][i] != f) dfs(V[x][i], x), R[x] += R[V[x][i]], B[x] += B[V[x][i]];
}
int main() {
  scanf("%d", &N);
  for (int i = (1); i <= (N); i++) scanf("%d", &C[i]);
  for (int i = (1); i <= (N); i++)
    if (C[i] == 1) Rs++;
  for (int i = (1); i <= (N); i++)
    if (C[i] == 2) Bs++;
  for (int i = (2); i <= (N); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    V[a].push_back(b);
    V[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = (2); i <= (N); i++)
    if ((R[i] == 0 || B[i] == 0) && (Rs - R[i] == 0 || Bs - B[i] == 0)) Ans++;
  printf("%d\n", Ans);
}
