// Slower C++ solution:
#include "bits/stdc++.h"

using namespace std;

#ifndef LOCAL

#define endl '\n'

#endif



#define fr(i, a, b) for(int i = a; i <= b; i++)

#define rf(i, a, b) for(int i = a; i >= b; i--)

#define pf push_front

#define pb push_back

#define eb emplace_back

#define fi first

#define se second

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

#define rall(x) x.rbegin(), x.rend()

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

#define lb lower_bound

#define ub upper_bound



typedef long long ll;

typedef long double f80;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;



int pct(int x) { return __builtin_popcount(x); }

int pct(ll x) { return __builtin_popcountll(x); }

int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))

int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }

ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }

int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }



vector<int> get_bits(int mask) {

	vector<int> bb;

	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }

	reverse(all(bb));

	return bb;

}



int get_mask(vector<int> v) {

	int mask = 0;

	for(int x : v) { mask ^= (1 << x); }

	return mask;

}



template<typename T>

void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }



mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());



ll rand(ll l, ll r){

	uniform_int_distribution<ll> uid(l, r);

	return uid(rng);

}



void sc() {}



template <typename Head, typename... Tail>

void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }



#ifdef LOCAL

#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#else

#define debug(...) 42

#endif



// #ifndef LOCAL

// string to_string(__int128 x) {

// 	string s = "";

// 	bool neg = 0;

// 	if(x < 0) { s += "-"; neg = 1; x = -x; }

// 	if(!x) s += '0';

// 	while(x) {

// 		int rem = x % 10;

// 		s += to_string(rem);

// 		x /= 10;

// 	}

// 	reverse(s.begin() + neg, s.end());

// 	return s;

// }

// #endif



const int mod = 1e9 + 7; // 998244353;



int pwr(int a,ll b) {

	int ans = 1;

	while(b) {

		if(b & 1) ans = (ans * 1LL * a) % mod;

		a = (a * 1LL * a) % mod;

		b >>= 1;

	}

	return ans;

}



/*

	Lookout for overflows!!

	Check array sizes!!

	Clear before test cases!!

	Use the correct modulo!!

	Check for corner cases!!

	Are you forgetting something?!

	Read problem statement carefully!!!

*/



const int N = 1e5 + 5;

vector<int> g[N];

ll a[N], val[N];



void dfs(int u,int p) {

    if(sz(g[u]) == 1) {

        val[u] = a[u];

        return;

    }

    ll s = 2 * a[u];

    ll mx = 0;

    for(int v : g[u]) {

        if(v != p) {

            dfs(v, u);

            s -= val[v];

            mx = max(mx, val[v]);

        }

    }

    val[u] = s;

    mx = max(mx, val[u]);

    if(2 * a[u] < 2 * mx || val[u] < 0) {

        cout << "NO";

        exit(0);

    }

}



void solve() {

	int n;

    sc(n);

    fr(i, 1, n)

        sc(a[i]);

    if(n == 2) {

        cout << ((a[1] == a[2]) ? "YES" : "NO");

        return;

    }

    fr(i, 1, n - 1) {

        int u, v;

        sc(u, v);

        g[u].pb(v);

        g[v].pb(u);

    }

    int r = 0;

    fr(i, 1, n) {

        if(sz(g[i]) > 1) r = i;

    }

    dfs(r, 0);

    if(val[r] > 0) {

        cout << "NO";

        return;

    }

    cout << "YES";

}



int main() {

	ios :: sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

	int t = 1;

	// cin >> t;

	for(int tt = 1; tt <= t; tt++) {

		solve();

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.6284248963548436x):
#include <iostream>

#include <cstdlib>

#include <cstdio>

using namespace std;

inline int read()

{

	int f = 1, x = 0;

	char ch;



	do{

		ch = getchar();

		if (ch == '-')

			f = -1;

	}while(ch < '0' || ch > '9');

	do{

		x = x * 10 + ch - '0';

		ch = getchar();

	}while(ch >= '0' && ch <= '9');

	return f * x;

}

const int N = 1e5;



int n;

int val[N + 1];

struct Edge {

	int to, next;

} edge[(N << 1) + 1];

int start[N + 1], tot;

int d[N + 1], up[N + 1];



inline void addedge(int u, int v)

{

	edge[++tot] = Edge{ v, start[u] };

	start[u] = tot;

	edge[++tot] = Edge{ u, start[v] };

	start[v] = tot;

	d[u]++;

	d[v]++;

	return;

}

inline bool dfs(int u, int fa)

{

	if (d[u] == 1) {

		up[u] = val[u];

		return false;

	}

	int sum = 0, maxx = 0;

	for (int i = start[u]; i; i = edge[i].next) {

		int v = edge[i].to;

		if (v != fa) {

			if (dfs(v, u))

				return true;

			sum += up[v];

			maxx = max(maxx, up[v]);

		}

	}

	up[u] = (val[u] << 1) - sum;

	if (up[u] < 0 || up[u] > val[u] || val[u] < maxx) {

		printf("NO\n");

		return true;

	}

	return false;

}

int main()

{

	n = read();

	for (int i = 1; i <= n; i++)

		val[i] = read();

	for (int i = 1; i < n; i++) {

		int u = read(), v = read();

		addedge(u, v);

	}

	if (n == 2) {

		if (val[1] == val[2])

			printf("YES\n");

		else

			printf("NO\n");

		return 0;

	}



	for (int i = 1; i <= n; i++) {

		if (d[i] > 1) {

			if (!dfs(i, 0)) {

				if (up[i])

					printf("NO\n");

				else

					printf("YES\n");

			}

			break;

		}

	}



	return 0;

}