#include <bits/stdc++.h>
using namespace std;
class Graph {
 public:
  explicit Graph(int n) : cols_(n), colors_subtree_(n), adj_(n) {}
  void SetColor(int node, int color) { cols_[node] = color; }
  int GetColor(int node) const { return cols_[node]; }
  int Solve() {
    CalculateColorsSubtree(0, -1);
    return Solve(0, -1, colors_subtree_[0]);
  }
  void Add(int from, int to) { adj_[from].push_back(to); }
  const vector<int>& GetNeighbors(int node) const { return adj_[node]; }

 private:
  void CalculateColorsSubtree(int node, int parent) {
    bool is_red = GetColor(node) == 1;
    bool is_blue = GetColor(node) == 2;
    pair<int, int> ans = {is_red, is_blue};
    for (int neighbor : GetNeighbors(node)) {
      if (neighbor == parent) continue;
      CalculateColorsSubtree(neighbor, node);
      const pair<int, int>& p = colors_subtree_[neighbor];
      ans.first += p.first;
      ans.second += p.second;
    }
    colors_subtree_[node] = ans;
  }
  int Solve(int node, int parent, pair<int, int> count) const {
    int ans = 0;
    for (int neighbor : GetNeighbors(node)) {
      if (neighbor == parent) continue;
      ans += Solve(neighbor, node, count);
      auto p = colors_subtree_[neighbor];
      if (p.first > 0 && p.second > 0) continue;
      auto new_count = count;
      new_count.first -= p.first;
      new_count.second -= p.second;
      if (new_count.first > 0 && new_count.second > 0) continue;
      ans++;
    }
    return ans;
  }
  vector<int> cols_;
  vector<pair<int, int>> colors_subtree_;
  vector<vector<int>> adj_;
};
int main() {
  int n;
  cin >> n;
  Graph g(n);
  vector<int> colors(n);
  for (int i = 0; i < n; i++) {
    int color;
    cin >> color;
    g.SetColor(i, color);
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    g.Add(a - 1, b - 1);
    g.Add(b - 1, a - 1);
  }
  cout << g.Solve() << endl;
  return 0;
}
