#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[300005];
bool vis[300005] = {false};
long long int color[300005] = {0};
vector<long long int> subtree[300005];
map<long long int, long long int> m[300005];
void dfs(long long int node) {
  vis[node] = true;
  long long int c = 0;
  m[node][color[node]]++;
  for (auto it : adj[node]) {
    if (!vis[it]) {
      dfs(it);
      c++;
      m[node][1] += m[it][1];
      m[node][2] += m[it][2];
    }
  }
}
int main() {
  long long int n;
  cin >> n;
  long long int countred = 0, countblue = 0;
  for (long long int i = 1; i <= n; i++) {
    cin >> color[i];
    if (color[i] == 1) countred++;
    if (color[i] == 2) countblue++;
  }
  for (long long int i = 1; i <= n - 1; i++) {
    long long int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1);
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int countr = 0, countb = 0;
    countr = m[i][1];
    countb = m[i][2];
    if (countr > 0 && countb > 0) continue;
    if ((countred - countr) > 0 && (countblue - countb) > 0)
      continue;
    else {
      ans++;
    }
  }
  cout << ans << "\n";
}
