#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
const long long int INF = 1011111111;
const long long int LLINF = 1000111000111000111LL;
const long double EPS = 1e-10;
const long double PI = 3.14159265358979323;
using namespace std;
long long int power(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return power((x * x), n / 2);
  else
    return x * power((x * x), (n - 1) / 2);
}
vector<long long int> g[3 * 100005];
bool visit[3 * 100005];
struct node {
  long long int color;
  long long int red;
  long long int blue;
};
long long int tr = 0, tb = 0, ans = 0;
node tree[3 * 100005];
void dfs(long long int nn) {
  visit[nn] = true;
  if (tree[nn].color == 1)
    tree[nn].red += 1;
  else if (tree[nn].color == 2)
    tree[nn].blue += 1;
  for (auto it : g[nn]) {
    if (!visit[it]) {
      dfs(it);
      tree[nn].red += tree[it].red;
      tree[nn].blue += tree[it].blue;
      long long int u, v;
      u = nn;
      v = it;
      if ((tree[v].blue == tb && tree[v].red == 0) ||
          (tree[v].red == tr && tree[v].blue == 0)) {
        ans++;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, i, j, k;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> tree[i].color;
    if (tree[i].color == 1)
      tr++;
    else if (tree[i].color == 2)
      tb++;
  }
  vector<pair<long long int, long long int> > ed(n - 1);
  for (i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0);
  cout << ans;
  cerr << '\n'
       << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
}
