#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<int> v[N];
short col[N];
int red, blue;
bool vis[N];
int ans[N][3];
void dfs(int node) {
  vis[node] = true;
  ans[node][col[node]] += 1;
  for (auto i : v[node]) {
    if (!vis[i]) {
      dfs(i);
      for (int j = 1; j <= 2; ++j) ans[node][j] += ans[i][j];
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, l, r, Ans(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> col[i];
    if (col[i])
      if (col[i] == 1)
        red += 1;
      else
        blue += 1;
  }
  for (int i = 1; i <= n - 1; ++i) {
    cin >> l >> r;
    v[l].push_back(r);
    v[r].push_back(l);
  }
  dfs(1);
  for (int i = 1; i <= n; ++i) {
    int r = ans[i][1], b = ans[i][2];
    if ((r == red && b == 0) || (b == blue && r == 0)) Ans++;
  }
  cout << Ans;
  return 0;
}
