#include <bits/stdc++.h>
using namespace std;
const int N = 1 + 3e5;
vector<vector<int>> edge(N);
int blue(0), red(0);
vector<bool> visited(N, false);
vector<char> color(N);
int cnt = 0;
pair<int, int> dfs(int u) {
  visited[u] = true;
  int bl, rd;
  bl = rd = 0;
  pair<int, int> res;
  for (int i = 0; i < edge[u].size(); i++) {
    if (!visited[edge[u][i]]) {
      res = dfs(edge[u][i]);
      bl += res.first;
      rd += res.second;
      if ((res.first == blue && res.second == 0) ||
          (res.first == 0 && res.second == red)) {
        cnt++;
      }
    }
  }
  bl += color[u] == '2';
  rd += color[u] == '1';
  return {bl, rd};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> color[i];
    red += color[i] == '1';
    blue += color[i] == '2';
  }
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  dfs(1);
  cout << cnt;
  return 0;
}
