#include <iostream>
#include <iomanip>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <cmath>
#include <complex>
#include <cfloat>

using namespace std;

#define INFD numeric_limits<double>::infinity()
#define INFL (int)1e8
#define INFLL (long long)1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

/*******************************************************/
struct tree_t {
  int n;           // |V|, index begins with 0
  int r;           // root
  vector<P> edges; // E
  vector<ll> cost; // cost or distance
};

class Tree {
private:
  struct node {
    int id; vi childs; int parent; ll cost; int deg; ll d; ll value;
    bool operator<(const node & another) const {
      return deg != another.deg ? deg < another.deg : id < another.id;
    }
  };
  int n;
public:
  vector<node> nodes;
  vi leaves;
  int root;
  Tree(tree_t T, vll a) {
    n = T.n;
    root = T.r;
    nodes.resize(n);
    Loop(i, n) nodes[i] = { i,{},-1,0,-1,0, a[i] };
    map<int, vector<pair<int, ll>>> edges;
    Loop(i, n - 1) {
      if (T.cost.size() == 0) {
        edges[T.edges[i].first].push_back({ T.edges[i].second,1 });
        edges[T.edges[i].second].push_back({ T.edges[i].first,1 });
      }
      else {
        edges[T.edges[i].first].push_back({ T.edges[i].second,T.cost[i] });
        edges[T.edges[i].second].push_back({ T.edges[i].first,T.cost[i] });
      }
    }
    leaves = {};
    stack<int> stk;
    stk.push(root);
    while (stk.size()) {
      int a = stk.top(); stk.pop();
      if (nodes[a].deg != -1) continue;
      if (a == root) nodes[a].deg = 0;
      int leaf_flag = true;
      Loop(i, edges[a].size()) {
        int b = edges[a][i].first;
        if (nodes[b].deg != -1) {
          nodes[a].parent = b;
          nodes[a].cost = edges[a][i].second;
          nodes[a].deg = nodes[b].deg + 1;
          nodes[a].d = nodes[b].d + nodes[a].cost;
        }
        else {
          leaf_flag = false;
          nodes[a].childs.push_back(b);
          stk.push(b);
        }
      }
      if (leaf_flag) leaves.push_back(a);
    }
    if (n == 1) leaves.push_back(root);
    return;
  }
  int solve(int focus) {
    int m = nodes[focus].childs.size();
    vll v(m);
    Loop(i, m) {
      v[i] = solve(nodes[focus].childs[i]);
      if (v[i] == -1) return -1;
    }
    if (m == 0) return nodes[focus].value;
    else if (m == 1) {
      if (v[0] == nodes[focus].value) {
        return nodes[focus].value;
      }
      else return -1;
    }
    else {
      ll sum = 0;
      ll max_v = 0;
      Loop(i, m) {
        sum += v[i];
        max_v = max(max_v, v[i]);
      }
      ll others_v = sum - max_v;
      ll capacity;
      if (max_v >= others_v) capacity = others_v;
      else capacity = sum / 2;
      if ((sum + 1) / 2 <= nodes[focus].value && nodes[focus].value <= sum) {
        ll y = sum - nodes[focus].value;
        ll x = sum - y * 2;
        if (y > capacity) return -1;
        else return x;
      }
      else return -1;
    }
  }
};

int main() {
  tree_t T;
  cin >> T.n;
  vll a(T.n); Loop(i, T.n) cin >> a[i];
  vi d(T.n, 0);
  Loop(i, T.n - 1) {
    int s, t; cin >> s >> t;
    T.edges.push_back({ s - 1, t - 1 });
    d[s - 1]++;
    d[t - 1]++;
  }
  bool ans;
  T.r = -1;
  Loop(i, T.n) {
    if (d[i] >= 2) {
      T.r = i;
      break;
    }
  }
  if (T.r == -1) {
    ans = true;
    Loop(i, T.n) {
      if (a[0] != a[i]) ans = false;
    }
  }
  else {
    Tree tree(T, a);
    if (tree.solve(T.r) == 0) ans = true;
    else ans = false;
  }
  if (ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 29908