#include <bits/stdc++.h>
using namespace std;
vector<int> graf[300000];
int boje[300000];
bool mark[300000];
int crveno = 0;
int plavo = 0;
int res = 0;
pair<int, int> dfs(int x) {
  mark[x] = true;
  int red = 0;
  int blue = 0;
  if (boje[x] == 1) red++;
  if (boje[x] == 2) blue++;
  for (int i = 0; i < graf[x].size(); i++) {
    if (!mark[graf[x][i]]) {
      pair<int, int> p = dfs(graf[x][i]);
      if ((crveno - p.first == 0 && p.second == 0) ||
          (p.first == 0 && plavo - p.second == 0)) {
        res++;
      }
      red += p.first;
      blue += p.second;
    }
  }
  return make_pair(red, blue);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> boje[i];
    if (boje[i] == 1) crveno++;
    if (boje[i] == 2) plavo++;
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graf[a].push_back(b);
    graf[b].push_back(a);
  }
  dfs(0);
  cout << res;
  return 0;
}
