import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    auto edges = new int[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        edges[s[0]-1] ~= s[1]-1;
        edges[s[1]-1] ~= s[0]-1;
    }


    bool dfs(int n, int p) {
        if (edges[n].map!(m => m != p).sum == 0) return true;
        bool ret = true;
        foreach (m; edges[n]) if (m != p) ret &= dfs(m, n);
        long s = edges[n].map!(m => m == p ? 0 : A[m]).sum;
        long x = s - A[n];
        A[n] = s - 2 * x;
        return x >= 0 && A[n] >= 0 && ret;
    }


    writeln( dfs(0, -1) ? "YES" : "NO" );
}
