#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v(300005);
vector<int> visit(300005, 0);
int dp[300005][3] = {0}, b[3];
int ans = 0, u;
void dfs(int x) {
  visit[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int z = v[x][i];
    if (visit[z] == 0) {
      dfs(z);
      dp[x][0] += dp[z][0];
      dp[x][1] += dp[z][1];
      dp[x][2] += dp[z][2];
      if ((dp[z][1] == 0 && dp[z][2] == b[2]) ||
          (dp[z][2] == 0 && dp[z][1] == b[1])) {
        ans++;
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]]++;
    dp[i][a[i]] = 1;
  }
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1);
  cout << ans;
}
