#include <bits/stdc++.h>

using namespace std;

typedef long long int64;

int64 N, A[100000];
vector< int > g[100000];

void rec(int idx, int par)
{
  if(g[idx].size() == 1) return;
  int64 ret = 0, large = 0;
  for(auto &to : g[idx]) {
    if(to == par) continue;
    rec(to, idx);
    ret += A[to];
    large = max(large, A[to]);
  }
  if(A[idx] > ret || ret > 2 * A[idx]) {
    puts("NO");
    exit(0);
  }
  int64 rest = ret - A[idx];
  if(rest > ret - large) {
    puts("NO");
    exit(0);
  }
  A[idx] -= rest;
}

int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  if(N == 2) {
    if(A[0] == A[1]) puts("YES");
    else puts("NO");
    return (0);
  }

  for(int i = 0; i < N; i++) {
    if(g[i].size() >= 2) {
      rec(i, -1);
      if(A[i] == 0) puts("YES");
      else puts("NO");
      return (0);
    }
  }

}
