#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
const double EPS = (1e-7);
const long long mod = (1e9 + 7), OO = 1e9, N = 3e5 + 5;
long long Ceil(long long x, long long y) { return (x + y - 1) / y; }
void run() {}
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long n, m, test = 1, cit;
vector<vector<int>> adj;
vector<int> co;
char city;
int vis[N], r[N], b[N];
void dfs(int u, int per) {
  vis[u] = 1;
  r[u] += co[u] == 1;
  b[u] += co[u] == 2;
  for (auto v : adj[u]) {
    if (v != per && !vis[v]) {
      dfs(v, u);
      r[u] += r[v];
      b[u] += b[v];
    }
  }
}
int main() {
  run();
  fast();
  test = -1;
  cin >> n;
  adj = vector<vector<int>>(n + 1);
  co.resize(n + 1);
  pair<int, int> p;
  for (int i = 1; i <= n; i++) {
    cin >> co[i];
    p.first += co[i] == 1;
    p.second += co[i] == 2;
  }
  m = n - 1;
  while (m--) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    if ((r[i] == p.first && b[i] == 0) || (r[i] == 0 && b[i] == p.second))
      cit++;
  }
  return cout << cit, 0;
}
