#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <functional>
#include <ctime>
#include <limits>
#include <tuple>
#include <complex>
#include <numeric>
#include <future>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define right _right

const ld pi = acos(-1.0);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
bool chmin(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

template<typename U, typename V>
ostream &operator<<(ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const vector<U> &x) {
    s << "[";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "]";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const set<U> &x) {
    s << "{";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "}";
    return s;
}

template<int sz>
ostream operator<<(ostream &s, const bitset<sz> &x) {
    for (int i = 0; i < sz; i++) {
        s << x[i];
    }
    return s;
}


//--------------------------------------------------------------------------
const int maxn = 1e5 + 5;
vector<int> g[maxn];
ll a[maxn];

ll dfs(int v, int p = -1) {
	if (g[v].size() == 1) {
		return a[v];
	}
	
	
	vector<ll> ch;
	ll r = 0;
	for (int to : g[v]) {
		if (to == p) {
			continue;
		}
		ch.pb(dfs(to, v));
		r += ch.back();
	}
	sort(ch.begin(), ch.end());
	
	ll already = r & 1;
	ch.back() -= r & 1;
	r -= r & 1;
	
	sort(ch.begin(), ch.end());
	
	
	ll bad = max(0LL, ch.back() - (r - ch.back()));
	ll diff = (r - bad) / 2;
	
	if (p == -1) {
		if (already || r / 2 != a[v] || ch.back() > r - ch.back()) {
			//cout << v << endl;
			//cout << ch << endl;
			cout << "NO" << endl;
			exit(0);
		}
	}
	
	
	if (!(r + already - diff <= a[v] && a[v] <= r + already)) {
		//cout << ch << endl;
		//cout << r << " " << already << " " << diff << endl;
		cout << "NO" << endl;
		exit(0);
	}
	
	ll need = r + already - a[v];
	
	
	
	return r + already - need * 2;
}

int deg[maxn];

int main() {
    srand(1231);


#ifdef LOCAL
	//gen();
	//return 0;
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
#endif

	//ofstream out("a.out");
	
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
		deg[u]++;
		deg[v]++;
	}
	
	int s = 1;
	for (int i = 1; i <= n; i++) {
		if (deg[i] > 1) {
			s = i;
		}
	}
	
	if (n == 2) {
		if (a[1] == a[2]) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	} else {
		dfs(s, -1);
		cout << "YES" << endl;
	}
	
	
	
	
    return 0;
}


Measured memory_bytes: 18304