#include <bits/stdc++.h>
using namespace std;
struct counter {
  int blue;
  int red;
  int count;
};
tuple<int, int> dfs(struct counter *structcounter, vector<vector<int>> &edges,
                    vector<int> &v_colors, int vertex, int parent) {
  int sum_red_vertex_sofar = 0;
  int sum_blue_vertex_sofar = 0;
  if (v_colors[vertex] == 1) {
    sum_red_vertex_sofar = 1;
  }
  if (v_colors[vertex] == 2) {
    sum_blue_vertex_sofar = 1;
  }
  tuple<int, int> sub_tree;
  for (auto adj_vertex : edges[vertex]) {
    if (adj_vertex == parent) {
      continue;
    }
    sub_tree = dfs(structcounter, edges, v_colors, adj_vertex, vertex);
    if (get<0>(sub_tree) == structcounter->red && get<1>(sub_tree) == 0) {
      structcounter->count++;
    }
    if (get<0>(sub_tree) == 0 && get<1>(sub_tree) == structcounter->blue) {
      structcounter->count++;
    }
    sum_red_vertex_sofar += get<0>(sub_tree);
    sum_blue_vertex_sofar += get<1>(sub_tree);
  }
  return make_tuple(sum_red_vertex_sofar, sum_blue_vertex_sofar);
}
int main() {
  int num_vertices;
  scanf("%d", &num_vertices);
  vector<int> v_colors(num_vertices + 1);
  struct counter structcounter;
  structcounter.blue = 0;
  structcounter.red = 0;
  structcounter.count = 0;
  int c;
  for (auto i = 1; i <= num_vertices; ++i) {
    scanf("%d", &c);
    if (c == 1) {
      structcounter.red++;
    }
    if (c == 2) {
      structcounter.blue++;
    }
    v_colors[i] = c;
  }
  vector<vector<int>> edges(num_vertices + 1);
  int x, y;
  for (auto i = 0; i < num_vertices - 1; ++i) {
    scanf("%d %d", &x, &y);
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  dfs(&structcounter, edges, v_colors, 1, -1);
  cout << structcounter.count << endl;
  return 0;
}
