#include <bits/stdc++.h>
using namespace std;
vector<int> v[300001];
class color {
 public:
  int b;
  int r;
} color[300001];
int col[300001];
bool visited[300001];
void dfs_visit(int curr) {
  if (col[curr] == 1) {
    color[curr].r = 1;
    color[curr].b = 0;
  } else if (col[curr] == 2) {
    color[curr].r = 0;
    color[curr].b = 1;
  } else {
    color[curr].r = 0;
    color[curr].b = 0;
  }
  if (v[curr].size() == 1 && curr != 1) {
    if (col[curr] == 1) {
      color[curr].r = 1;
      color[curr].b = 0;
    } else if (col[curr] == 2) {
      color[curr].r = 0;
      color[curr].b = 1;
    } else {
      color[curr].r = 0;
      color[curr].b = 0;
    }
    return;
  }
  for (int i = 0; i < v[curr].size(); i++) {
    if (!visited[v[curr][i]]) {
      visited[v[curr][i]] = 1;
      dfs_visit(v[curr][i]);
      color[curr].b += color[v[curr][i]].b;
      color[curr].r += color[v[curr][i]].r;
    }
  }
  return;
}
void dfs(int n) {
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      visited[i] = 1;
      dfs_visit(i);
    }
  }
}
int main() {
  int n;
  cin >> n;
  int i;
  int red = 0, blue = 0;
  for (i = 1; i <= n; i++) {
    cin >> col[i];
    if (col[i] == 1) {
      red++;
    } else if (col[i] == 2) {
      blue++;
    }
  }
  int p, c;
  for (i = 1; i <= n - 1; i++) {
    cin >> p >> c;
    v[p].push_back(c);
    v[c].push_back(p);
  }
  dfs(n);
  int count = 0;
  for (i = 2; i <= n; i++) {
    if (color[i].b >= 1 && color[i].r >= 1) {
      continue;
    } else {
      if (red - (color[i].r) >= 1 && blue - (color[i].b) >= 1) {
        continue;
      } else {
        count++;
      }
    }
  }
  cout << count;
}
