#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>> &adj, int node, int colors[],
         vector<vector<int>> &colorCount, vector<bool> &visited) {
  if (colors[node] == 1) colorCount[node][0] = 1;
  if (colors[node] == 2) colorCount[node][1] = 1;
  for (int i = 0; i < adj[node].size(); i++) {
    if (!visited[adj[node][i]]) {
      visited[adj[node][i]] = true;
      dfs(adj, adj[node][i], colors, colorCount, visited);
      colorCount[node][0] += colorCount[adj[node][i]][0];
      colorCount[node][1] += colorCount[adj[node][i]][1];
    }
  }
}
void bfs(vector<vector<int>> &adj, int *result, int node,
         vector<vector<int>> &colorCount) {
  vector<bool> visited(adj.size(), false);
  visited[node] = true;
  queue<int> q;
  q.push(node);
  int temp;
  int a, b;
  while (!q.empty()) {
    temp = q.front();
    q.pop();
    for (int i = 0; i < adj[temp].size(); i++) {
      if (!visited[adj[temp][i]]) {
        q.push(adj[temp][i]);
        visited[adj[temp][i]] = true;
        if ((colorCount[0][0] - colorCount[adj[temp][i]][0] == 0 ||
             colorCount[0][1] - colorCount[adj[temp][i]][1] == 0) &&
            (colorCount[adj[temp][i]][0] == 0 ||
             colorCount[adj[temp][i]][1] == 0))
          *result += 1;
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  int colors[n];
  for (int i = 0; i < n; i++) {
    cin >> colors[i];
  }
  vector<vector<int>> adj(n);
  int temp, temp1;
  for (int i = 0; i < n - 1; i++) {
    cin >> temp >> temp1;
    adj[temp - 1].push_back(temp1 - 1);
    adj[temp1 - 1].push_back(temp - 1);
  }
  vector<vector<int>> colorCount(n, vector<int>(2, 0));
  vector<bool> visited(n, false);
  visited[0] = true;
  dfs(adj, 0, colors, colorCount, visited);
  int result = 0;
  bfs(adj, &result, 0, colorCount);
  cout << result;
  return 0;
}
