#include <bits/stdc++.h>
using namespace std;
vector<int> adjlist[300005];
int cnt[3];
int dp[300005][3];
int ans = 0;
int a[300005];
void dfs(int node, int par) {
  dp[node][a[node]]++;
  for (int i : adjlist[node]) {
    if (i != par) {
      dfs(i, node);
      for (int j = 0; j < 3; ++j) {
        dp[node][j] += dp[i][j];
      }
      int blue = cnt[1] - dp[i][1];
      int red = cnt[2] - dp[i][2];
      if ((blue == 0 or red == 0) and (dp[i][1] == 0 or dp[i][2] == 0)) {
        ++ans;
      }
    }
  }
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    adjlist[x].push_back(y);
    adjlist[y].push_back(x);
  }
  dfs(1, 0);
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
