#include <bits/stdc++.h>
using namespace std;
struct node {
  int label;
  int red;
  int blue;
  vector<int> children;
  int parent;
  bool added;
  bool visited;
};
node tree[300001];
int Direct(int root) {
  if (tree[root].visited) return 0;
  tree[root].visited = true;
  int i, parent, tmp;
  tmp = tree[root].children.size();
  for (i = 0; i < tmp; i++) {
    if (tree[tree[root].children[i]].visited) {
      tree[root].children[i] = tree[root].children[tmp - 1];
      tree[root].children.pop_back();
    } else {
      tree[tree[root].children[i]].parent = root;
      Direct(tree[root].children[i]);
    }
  }
  return 0;
}
int DFS(int root) {
  int i, parent;
  for (i = 0; i < tree[root].children.size(); i++) DFS(tree[root].children[i]);
  parent = tree[root].parent;
  if (parent == root) return 1;
  tree[parent].red += tree[root].red;
  tree[parent].blue += tree[root].blue;
  return 0;
}
int main() {
  int n, i, color, vertex1, vertex2, r1, r2;
  cin >> n;
  for (i = 1; i <= n; i++) {
    tree[i].label = i;
    tree[i].red = 0;
    tree[i].blue = 0;
    tree[i].added = false;
    tree[i].parent = i;
    tree[i].visited = false;
  }
  for (i = 1; i <= n; i++) {
    cin >> color;
    if (color == 1)
      tree[i].red++;
    else if (color == 2)
      tree[i].blue++;
  }
  for (i = 0; i < n - 1; i++) {
    cin >> vertex1 >> vertex2;
    tree[vertex1].children.push_back(vertex2);
    tree[vertex2].children.push_back(vertex1);
  }
  Direct(1);
  int j, l, nice = 0;
  DFS(1);
  for (i = 2; i <= n; i++)
    if (!((tree[i].red > 0 && tree[i].blue > 0) ||
          ((tree[1].red - tree[i].red) > 0 &&
           (tree[1].blue - tree[i].blue) > 0)))
      nice++;
  cout << nice << endl;
  return 0;
}
