#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long mod = 998244353;
const int N = 3e5 + 4;
int n;
vector<int> adj[N];
int col[3][N], a[N], u, v;
int tot[3], ans = 0;
void dfs(int i, int p) {
  col[a[i]][i]++;
  for (auto x : adj[i]) {
    if (x == p) continue;
    dfs(x, i);
    if ((col[1][x] == 0 || col[2][x] == 0) &&
        (col[1][x] == tot[1] || col[2][x] == tot[2]))
      ans++;
    for (int j = 0; j < 3; j++) col[j][i] += col[j][x];
  }
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    tot[a[i]]++;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset(col, 0, sizeof(col));
  dfs(0, -1);
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
