#include <bits/stdc++.h>
using namespace std;
vector<long long int> arr[300003];
long long int color[300009];
long long int dp[300002][3];
bool vis[300002] = {0};
bool visited[300002] = {0};
long long int red = 0, blue = 0;
void dfs(long long int x, long long int y) {
  visited[x] = true;
  for (auto& i : arr[x]) {
    if (visited[i] == false) {
      dfs(i, x);
    }
  }
  dp[y][1] = dp[y][1] + dp[x][1];
  dp[y][2] = dp[y][2] + dp[x][2];
}
long long int cnt = 0;
void dfs2(long long int x, long long int y) {
  vis[x] = true;
  long long int a = dp[x][1], b = dp[x][2];
  if (!(a > 0 && b > 0) && !(red - dp[x][1] > 0 && blue - dp[x][2] > 0)) {
    cnt++;
  }
  for (auto& i : arr[x]) {
    if (vis[i] == false) {
      dfs2(i, x);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> color[i];
    if (color[i] == 2) {
      dp[i][2] = 1;
      blue++;
    }
    if (color[i] == 1) {
      dp[i][1] = 1;
      red++;
    }
  }
  for (long long int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    arr[x].push_back(y);
    arr[y].push_back(x);
  }
  dfs(1, 0);
  dfs2(1, 0);
  cout << cnt;
}
