#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <unordered_set>

unsigned readUnsigned() {
    int c;
    do { c = ::getchar_unlocked(); } while (c < '0');
    unsigned result = c - '0';
    while ((c = ::getchar_unlocked()) >= '0') {
        result *= 10;
        result += c - '0';
    }
    return result;
}

const unsigned MAX_N = 100 * 1000;

struct Node {
    unsigned A = 0;
    std::unordered_set<unsigned> edges;
};

unsigned N;
Node T[MAX_N];

bool possible() {
    std::queue<unsigned> Q;
    for (unsigned i = 0; i < N; ++i) {
        for (unsigned j : T[i].edges) {
            if (T[j].edges.size() == 1) {
                Q.push(*T[j].edges.begin());
            }
        }
    }

    std::unordered_set<unsigned> done;
    while (!Q.empty()) {
        unsigned i = Q.front();
        Q.pop();
        if (done.count(i)) {
            continue;
        }

        if (T[i].edges.empty()) {
            done.insert(i);
            continue;
        }

        uint64_t leafA = 0;
        uint64_t maxLeafA = 0;
        uint64_t otherA = 0;
        std::unordered_set<unsigned> leaves;
        for (unsigned j : T[i].edges) {
            if (T[j].edges.size() == 1) {
                leaves.insert(j);
                leafA += T[j].A;
                maxLeafA = std::max<uint64_t>(maxLeafA, T[j].A);
            }
            else {
                otherA += T[j].A;
            }
        }

        if (leaves.empty()) {
            continue;
        }

        if (T[i].edges.size() - leaves.size() > 1) {
            continue;
        }

        if (leaves.size() == 1) {
            if (T[i].edges.size() == 1) {
                unsigned leaf = *leaves.begin();
                if (T[leaf].A != T[i].A) {
                    return false;
                }
                T[leaf].A = 0;
                T[i].A = 0;
                break;
            }
            if (T[i].edges.size() == 2) {
                unsigned leaf = *leaves.begin();
                T[i].edges.erase(leaf);
                unsigned parent = *T[i].edges.begin();
                Q.push(parent);
                done.insert(leaf);
                if (T[leaf].A != T[i].A) {
                    return false;
                }
                T[leaf].A = 0;
            }
            continue;
        }

        if (leafA < T[i].A) {
            return false;
        }
        uint64_t leafPaths = leafA - T[i].A;
        if (leafA > 2 * T[i].A) {
            return false;
        }
        uint64_t outPaths = T[i].A - leafPaths;
        if (outPaths > otherA) {
            return false;
        }
        if (outPaths + 2 * leafPaths != leafA) {
            return false;
        }
        if (maxLeafA > leafPaths + outPaths) {
            return false;
        }

        for (unsigned l : leaves) {
            done.insert(l);
            T[i].edges.erase(l);
            T[l].A = 0;
        }

        assert(T[i].edges.size() <= 1);
        if (T[i].edges.size() == 1) {
            Q.push(*T[i].edges.begin());
        }

        T[i].A -= leafPaths;
    }

    for (unsigned i = 0; i < N; ++i) {
        if (T[i].A != 0) {
            return false;
        }
    }

    return true;
}

int main() {
    N = readUnsigned();
    for (unsigned i = 0; i < N; ++i) {
        T[i].A = readUnsigned();
    }

    for (unsigned i = 0; i < N - 1; ++i) {
        unsigned x = readUnsigned();
        unsigned y = readUnsigned();
        --x, --y;
        T[x].edges.insert(y);
        T[y].edges.insert(x);
    }

    puts(possible() ? "YES" : "NO");
}


Measured memory_bytes: 18980