Language: C++

#include <bits/stdc++.h>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

vector<ll> stones(100000), used(100000);
vector<int> tree[100000];

int dfs(int node){
    used[node] = 1;

    int n = (int)tree[node].size();

    if(node != 0 && n == 1) return stones[node];

    vector<ll> edges(n+1, 0);
    ll total = 0;
    rep(n){
        if(used[next]) continue;
        edges[i] = dfs(tree[node][i]);
        total += edges[i];
        if(edges[i] == INT_MAX) return INT_MAX;
        // cerr << node+1 << "->" << next+1 << ": " << edges[i] << endl;
    }
    edges[n] = (stones[node]*2-total);
    if(edges[n] < 0) return INT_MAX;
    total += edges[n];
    for(ll edge: edges){
        if(edge > total/2) return INT_MAX;
    }
    return edges[n];
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    rep(n) cin >> stones[i];
    rep(n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }

    
    cout << (dfs(0)==INT_MAX?"NO":"YES") << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int dfs(int)':
a.cc:29:16: error: no match for 'operator[]' (operand types are 'std::vector<long long int>' and '<unresolved overloaded function type>')
   29 |         if(used[next]) continue;
      |                ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long long int; _Alloc = std::allocator<long long int>; const_reference = const long long int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~