#include <bits/stdc++.h>
using namespace std;
void dfs(int u, const vector<vector<int> > &a, const vector<int> &c,
         vector<int> &p, vector<int> &cntRed, vector<int> &cntBlue) {
  if (c[u] == 1) {
    cntRed[u] = 1;
  } else if (c[u] == 2) {
    cntBlue[u] = 1;
  }
  for (int v : a[u]) {
    if (p[v] != -1) {
      continue;
    }
    p[v] = u;
    dfs(v, a, c, p, cntRed, cntBlue);
    cntRed[u] += cntRed[v];
    cntBlue[u] += cntBlue[v];
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> c(n), p(n, -1), cntRed(n), cntBlue(n);
  vector<vector<int> > a(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    a[u - 1].push_back(v - 1);
    a[v - 1].push_back(u - 1);
  }
  p[0] = 0;
  dfs(0, a, c, p, cntRed, cntBlue);
  int ans = 0;
  for (int v = 1; v < n; ++v) {
    int cntRedP = cntRed[0] - cntRed[v];
    int cntBlueP = cntBlue[0] - cntBlue[v];
    if (cntRedP && cntBlueP) {
      continue;
    }
    if (cntRed[v] && cntBlue[v]) {
      continue;
    }
    ++ans;
  }
  cout << ans;
}
