#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n, c[300001], ans, r, b, dp[300001][2];
vector<int> g[300001];
void dfs(int p, int cur) {
  for (int i : g[cur]) {
    if (i != p) {
      dfs(cur, i);
      dp[cur][0] += dp[i][0];
      dp[cur][1] += dp[i][1];
    }
  }
  dp[cur][max(0, c[cur] - 1)] += (c[cur] > 0);
}
void calc(int p, int cur) {
  if (p != 0 && !((((dp[cur][0] > 0) + (dp[cur][1] > 0)) == 2) +
                  ((((r - dp[cur][0]) > 0) + ((b - dp[cur][1]) > 0)) == 2)))
    ans++;
  for (int i : g[cur]) {
    if (p != i) calc(cur, i);
  }
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    if (c[i] == 1)
      r++;
    else if (c[i] == 2)
      b++;
  }
  for (int i = 1; i <= n - 1; i++) {
    int first, second;
    cin >> first >> second;
    g[first].push_back(second);
    g[second].push_back(first);
  }
  dfs(0, 1);
  calc(0, 1);
  cout << ans;
}
