#include <bits/stdc++.h>
using namespace std;
struct A {
  int red, blue;
  A() { red = blue = 0; }
} col[300010];
int da[300010];
bool vis[300010];
vector<int> G[300010];
void dfs(int x) {
  vis[x] = 1;
  col[x].red = col[x].blue = 0;
  if (da[x] == 1) ++col[x].red;
  if (da[x] == 2) ++col[x].blue;
  for (int i = 0; i < G[x].size(); ++i) {
    int to = G[x][i];
    if (vis[to]) continue;
    dfs(to);
    col[x].red += col[to].red;
    col[x].blue += col[to].blue;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &da[i]);
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(1);
  int tolr = col[1].red, tolb = col[1].blue, ans = 0;
  for (int i = 2; i <= n; ++i) {
    if ((tolr - col[i].red == 0 || tolb - col[i].blue == 0) &&
        (col[i].blue == 0 || col[i].red == 0))
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}
