// Slower C++ solution:
#include <iostream>

#include <cmath>

#include <algorithm>

#include <cstdio>

#include <string>

#include <map>

#include <set>

#include <locale.h>

#include <vector>

#include <iomanip>

#include <cassert>

#include <list>

#include <unordered_map>

#include <cstring>



#define all(x) x.begin(), x.end()

#define sz(x) (int)(x.size())

#define pb push_back



#define onlycin ios_base::sync_with_stdio(false); cin.tie(0)

#define mp make_pair

#define endl "\n"

#define rep(i,x,y) for(int i = x; i <= y; ++i)

#define repr(i,x,y) for(long long i = x; i >= y; --i)

#define y1 wearsdfasdf

#define fi first

#define se second



typedef long long ll;



const int N = (100000) + 322;

const int INF = (ll)(1e9) + 7;



using namespace std;



int n, cost[N], flag;



vector <int> v[N];



vector <int> lst;



int getC(int sum, int mx) {

  if (sum / 2 < mx) return sum - mx;

  return sum / 2;

}



bool check(int sum, int av) {

  return (sum / 2 <= av && av <= sum);

}



void dfs(int x, int p = -1) {

  int sum = 0, mx = 0;

  for(auto it : v[x]) {

    if (p == it) continue;

    dfs(it, x);

    sum += cost[it];

    mx = max(mx, cost[it]);

  }

  if (sz(v[x]) > 1) {

   // cout << x << ' ' << sum << ' ' << mx << ' ' << cost[x] << ' ' << getC(sum, mx) << endl;

    if (!check(sum, cost[x])) {flag = 1;}

    int C = sum - cost[x];

    if (C > getC(sum, mx)) flag = 1;

    cost[x] = cost[x] - C;

  }

}



int main () {

  ios_base::sync_with_stdio(false);

  cin >> n;

  rep(i, 1, n) cin >> cost[i];

  rep(i, 1, n - 1) {

    int x, y; cin >> x >> y;

    v[x].pb(y);

    v[y].pb(x);

  }

  int root = 1;

  rep(i, 1, n) {

    if (sz(v[i]) > 1) root = i;

  }

  if (n == 2) {

    if (cost[1] != cost[2]) {

      cout << "NO";

      return 0;

    }

    cout << "YES";

    return 0;

  }

  

  dfs(root);

  if (cost[root] != 0) {

    cout << "NO";

    return 0;

  }

  if (flag == 1) {

    cout << "NO";

    return 0;

  }

  cout << "YES";

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.6304077737247646x):
#include <bits/stdc++.h>

using namespace std;



#define Int register int

#define MAXN 100005



template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}

template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}

template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}



int n,a[MAXN],f[MAXN],deg[MAXN];

struct edge{

	int v,nxt;

}e[MAXN << 1];

int top = 1,head[MAXN];

void Add_Edge (int u,int v){

	e[++ top] = edge {v,head[u]};head[u] = top;

	e[++ top] = edge {u,head[v]};head[v] = top;

}



bool dfs (int u,int fa){

	if (deg[u] == 1) return f[u] = a[u],1;

	f[u] = 2 * a[u];int Maxn = 0;

	for (Int i = head[u];i;i = e[i].nxt){

		int v = e[i].v;

		if (v == fa) continue;

		if (!dfs (v,u)) return 0;

		f[u] -= f[v],Maxn = max (Maxn,f[v]);

	}

	if (0 <= f[u] && f[u] <= a[u] && Maxn <= a[u]) return 1;

	else return 0;

}



signed main(){

	read (n);

	for (Int i = 1;i <= n;++ i) read (a[i]);

	for (Int i = 2,u,v;i <= n;++ i) read (u,v),Add_Edge (u,v),deg[u] ++,deg[v] ++;

	if (n == 2) return puts (a[1] == a[2] ? "YES" : "NO"),0;

	for (Int i = 1;i <= n;++ i) if (deg[i] > 1) return puts (dfs (i,0) && !f[i] ? "YES" : "NO"),0;

	return 0;

}