#include <bits/stdc++.h>
using namespace std;
int ans = 0, red = 0, bl = 0, n;
pair<long long, long long> dfs(list<int>* adj, int i, bool* visited,
                               int* color) {
  if (visited[i]) return make_pair(0, 0);
  visited[i] = 1;
  int x = 0, y = 0;
  for (auto it : adj[i]) {
    pair<long long, long long> t = dfs(adj, it, visited, color);
    x += t.first;
    y += t.second;
  }
  if (color[i] == 1) x++;
  if (color[i] == 2) y++;
  if ((x == 0 && y == bl) || (x == red && y == 0)) ans++;
  return make_pair(x, y);
}
int main() {
  long long u, v, c;
  cin >> n;
  list<int> adj[n + 1];
  bool visited[n + 1];
  int color[n + 1];
  for (int i = 1; i <= n; ++i) {
    cin >> color[i];
    if (color[i] == 1) red++;
    if (color[i] == 2) bl++;
  }
  memset(visited, 0, sizeof(visited));
  for (int i = 1; i < n; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(adj, 1, visited, color);
  cout << ans;
  return 0;
}
