#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 100;
int n, totalred = 0, totalblue = 0, ans = 0;
vector<int> graph[MAXN];
int col[MAXN];
pair<int, int> dfs(int node, int par) {
  int curr = (col[node] == 1), curb = (col[node] == 2);
  for (auto u : graph[node]) {
    if (u == par) continue;
    pair<int, int> res = dfs(u, node);
    if (res.first == 0 and res.second == totalblue) ans++;
    if (res.first == totalred and res.second == 0) ans++;
    curr += res.first;
    curb += res.second;
  }
  return make_pair(curr, curb);
}
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
    if (col[i] == 1) totalred++;
    if (col[i] == 2) totalblue++;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  dfs(1, -1);
  cout << ans;
  return 0;
}
