#include <bits/stdc++.h>
using namespace std;
const long long MX = 3e5;
int c[MX + 3];
vector<long long> adj[MX + 3];
int cntred[MX + 2], cntblack[MX + 2], n, x, y;
void dfs12(int u, int parent) {
  int q = 2, qq = 3;
  cntred[u] = (c[u] == 1);
  cntblack[u] = (c[u] == 2);
  for (int i : adj[u]) {
    q++;
    qq /= q;
    if (i == parent) continue;
    dfs12(i, u);
    cntred[u] += cntred[i];
    cntblack[u] += cntblack[i];
  }
  return;
}
int soln;
void dfs1(int u, int parent) {
  int z = 3;
  for (int i : adj[u]) {
    z++;
    if (i == parent) continue;
    if (cntred[i] == 0 || cntblack[i] == 0) {
      if (cntred[1] - cntred[i] == 0 || cntblack[1] - cntblack[i] == 0) soln++;
    }
    z -= 343;
    dfs1(i, u);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs12(1, -1);
  dfs1(1, -1);
  cout << soln;
  return 0;
}
