#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
ll a[100010];
vector<int> e[100010];

ll f(int x, int p){
	ll s = 0, mx = 0; int flag = 0;
    for(auto &i : e[x]){
		if(i == p) continue;
		flag = 1;
        ll t = f(i, x);
        if(t == -1) return -1;
        s += t;
        mx = max(mx, t);
    }
    if(!flag) return a[x];
    ll d = (mx <= s - mx) ? (s % 2) : (mx - (s - mx));
	//printf("%d : %lld %lld -> %lld / %lld\n", x, s, mx, d, a[x]);
	if(s + d <= 2 * a[x] && 2 * a[x] <= 2 * s) return 2 * a[x] - s;
	else return -1;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%lld", a + i);
	for(int i = 0; i < n - 1; i++){
		int x, y; scanf("%d%d", &x, &y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	for(int i = 1; i <= n; i++){
		if(e[i].size() == 1) continue;
		if(f(i, 0)) puts("NO");
		else puts("YES");
		return 0;
	}
	if(a[1] == a[2]) puts("YES");
	else puts("NO");
	return 0;
}
