#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

int a[100000];
vector<int>E[100000];
int s;
int dfs(int u, int p) {
	int cnt = 0, Max = 0;
	for (int v : E[u]) {
		if (v != p) {
			int a = dfs(v, u);
			cnt += a; Max = max(Max, a);
		}
	}
	if (s == u)return a[u] - cnt;
	if (E[u].size() == 1)return a[u];
	if (a[u] * 2 < cnt || Max > a[u] || a[u] * 2 - cnt > a[u]) {
		puts("NO"); exit(0);
	}
	return a[u] * 2 - cnt;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &a[i]);
	rep(i, n - 1) {
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		E[a].push_back(b); E[b].push_back(a);
	}
	rep(i, n) {
		if (E[i].size() == 1)s = i;
	}
	puts(dfs(s, -1) ? "NO" : "YES");
}