//MIPT Cryptozoology
//Room 265
#define _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:128000000")
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <stack>
#include <bitset>
#include <set>
#include <map>
#include <cassert>
#include <memory.h>
#include <sstream>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define itn int

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

typedef long long li;
typedef long long i64;
typedef long double ld;
typedef vector<int> vi;
typedef pair <int, int> pi;

void solve(bool);

void precalc();

int TESTNUM = 0;
#define FILENAME ""

int main() {
	string s = FILENAME;
#ifdef YA
	//assert(!s.empty());
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//cerr<<FILENAME<<endl;
	//assert (s != "change me please");
	clock_t start = clock();
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen(FILENAME ".in", "r", stdin);
	//freopen(FILENAME ".out", "w", stdout);
	cin.tie(0);
#endif
	cout.sync_with_stdio(0);
	cout.precision(10);
	cout << fixed;
	precalc();
	int t = 1;
	//cin >> t;
	int test_num = 1;
	while (t--) {
		//cout << "Case #" << test_num++ << ": ";
		++TESTNUM;
		solve(true);
	}
#ifdef YAH
	while (true) {
		solve(false);
	}
#endif
#ifdef YA
	cerr << "\n\n\n" << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n\n";
#endif
	return 0;
}

//#define int li

/*int pr[] = { 97, 2011 };
int mods[] = { 1000000007, 1000000009 };

const int C = 100500;
int powers[2][C];*/

//int MOD = 1000000007;

//int c[5010][5010];

template<typename T>
T binpow(T q, T w, T mod) {
	if (!w)
		return 1 % mod;
	if (w & 1)
		return q * 1LL * binpow(q, w - 1, mod) % mod;
	return binpow(q * 1LL * q % mod, w / 2, mod);
}

void precalc() {

	/*for (int w = 0; w < 2; ++w) {
	powers[w][0] = 1;
	for (int j = 1; j < C; ++j) {
	powers[w][j] = (powers[w][j - 1] * 1LL * pr[w]) % mods[w];
	}
	}*/

	/*for (int i = 0; i < 5010; ++i) {
	c[i][i] = c[i][0] = 1;
	for (int j = 1; j < i; ++j) {
	c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
	}
	}*/
}

template<typename T>
T gcd(T q, T w) {
	while (w) {
		q %= w;
		swap(q, w);
	}
	return q;
}
template<typename T>
T lcm(T q, T w) {
	return q / gcd(q, w) * w;
}

inline int nxt(){
	int x;
	cin >> x;
	return x;
}

#define int li

vector<int> a;
vector<vector<int>> g;

bool ANS = true;

int dfs(int v, int p) {
	vector<int> nex;
	for (int to : g[v]) {
		if (to == p) {
			continue;
		}
		nex.push_back(dfs(to, v));
	}
	if (nex.empty()) {
		return a[v];
	}
	int sum = 0, mx = 0;
	for (int x : nex) {
		sum += x;
		mx = max(mx, x);
	}
	if (sum < a[v]) {
		ANS = false;
		return 0;
	}
	int paired = sum - a[v];
	if (sum - mx < paired) {
		ANS = false;
		return 0;
	}
	if (paired > a[v]) {
		ANS = false;
		return 0;
	}
	return a[v] - paired;
}

void solve(bool read) {
	int n;
	cin >> n;
	a.resize(n);
	g.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i < n; ++i) {
		int c, b;
		cin >> c >> b;
		--c; --b;
		g[c].push_back(b);
		g[b].push_back(c);
	}
	if (n == 1) {
		if (a[0]) {
			cout << "NO\n";
		}
		else {
			cout << "YES\n";
		}
		return;
	}
	if (n == 2) {
		if (a[0] == a[1]) {
			cout << "YES\n";
		}
		else {
			cout << "NO\n";
		}
		return;
	}

	int root = 0;
	while (g[root].size() == 1) {
		++root;
	}

	int rest = dfs(root, root);
	if (rest == 0 && ANS) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}

}



Measured memory_bytes: 14464