criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
vector<int> v[100005];
LL val[100005];
LL Max[100005];
LL Min[100005];
int ok=1;
void dfs(int x,int f){
    if(v[x].size()==1&&f!=0){
        Max[x]=val[x];
        Min[x]=val[x]&1;
        return ;
    }
    vector<pll> tmp;
    for(auto it:v[x]){
        if(it!=f){
            dfs(it,x);
            tmp.pb(mp(Max[it],Min[it]));
        }
    }
   // printf("%d",x);
    sort(tmp.begin(),tmp.end());
    for(auto it:tmp){
        Max[x]+=it.x;
      //  printf(" %lld %lld",it.x,it.y);
    }
  //  printf("\n");
    if(tmp.back().y>Max[x]-tmp.back().x){
        Min[x]=max(tmp.back().y-(Max[x]-tmp.back().x),2*val[x]-Max[x]);
    }
    else{
        Min[x]=max(Max[i]&1,2*val[x]-Max[x]);
    }
   /* if(val[x]%2!=Max[x]%2){
        ok=0;
    }*/
    if(val[x]>Max[x]){
        ok=0;
    }
    Max[x]=val[x];
    if(tmp.size()==1){
        Min[x]=val[x];
    }
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%lld",&val[i]);
    for(int i = 1;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }
    if(n==2){
        if(val[1]%2==val[2]%2){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    else{
        for(int i=1;i<=n;i++){
            if(v[i].size()!=1){
                dfs(i,0);
                if(Min[i]!=0){
                    ok=0;
                }
                break;
            }
        }
        int tot=0;
        for(int i = 1;i<=n;i++){
            if(v[i].size()==1){
                tot+=val[i];
            }
        }
        if(tot&1)ok=0;
        if(ok){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:52:24: error: 'i' was not declared in this scope
   52 |         Min[x]=max(Max[i]&1,2*val[x]-Max[x]);
      |                        ^
Language: C++

#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr <<"debug "<< i << std::endl;

//const ll MOD = 998244353;
const ll MOD = 1e9+7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n;
  std::cin>>n;

  std::vector<ll> a(n),v(n,LLONG_MAX),sort;
  rep(i,0,n)std::cin>>a[i];

  std::vector<std::vector<ll>> graph(n);
  rep(i,0,n-1){
    ll x,y;
    std::cin>>x>>y;
    x--;y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }

  if(n==2){
    std::cout<<((a[0]==a[1])?"YES":"NO");
    return 0;
  }

  ll root=-1;
  rep(i,0,n){
    if(graph[i].size()>=2)root=i;
  }

  std::vector<bool> used(n,false);
  std::queue<ll> que;

  que.push(root);

  while(!que.empty()){
    ll now=que.front();que.pop();
    sort.push_back(now);used[now]=true;
    for(ll next:graph[now]){
      if(!used[next])que.push(next);
    }    
  }

  for(ll i=n-1;i>=0;i--){
    ll now=sort[i];
    ll sum=0,max=-1;
    for(ll next:graph[now]){
      if(v[next]!=LLONG_MAX){
        sum+=v[next];
        max=std::max(max,v[next]);
      }
    }

    if(sum==0){
      v[now]=a[now];
    }else{
      v[now]=2*a[now]-sum;
      if(v[now]<0){
        std::cout<<"NO";
        return 0;
      }
      ll pair=(sum-v[now])/2;
      if(pair<0){
        std::coout<<"NO";
        return 0;
      }
      if(max>sum/2){
        if(sum-max<pair){
          std::cout<<"NO";
          return 0;
        }
      }else{
        if(sum/2<pair){
          std::cout<<"NO";
          return 0;
        }
      }
    }
  }

  if(v[root]!=0){
    std::cout<<"NO";
    return 0;
  }

  std::cout<<"YES";

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:93:14: error: 'coout' is not a member of 'std'; did you mean 'cout'?
   93 |         std::coout<<"NO";
      |              ^~~~~
      |              cout
Language: C++

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

int n;
vector<vector<int>> v(100010);
ll a[100010];
bool used[100010];

bool pos = true;

ll dfs(int p){
    used[p] = true;

    bool leaf = true;
    ll sum = 0, MAX = 0;
    for(auto i:v[p]){
        if(!used[i]){
            ll t = dfs(i);
            leaf = false;
            MAX = max(MAX,t);
            sum += t;
        }
    }
    if(leaf) return a[p];

    if(sum<a[p]){
        pos = false;
        return -1;
    }

    if( (sum-a[p]) <= min(sum-MAX,sum/2) ){
        ll ret = a[p] - (sum-a[p])
        return ret;
    }

    pos = false;
    return -1;
}

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        int r,b;
        cin>>r>>b;
        r--,b--;
        v[r].push_back(b);
        v[b].push_back(r);
    }
    

    ll r = dfs(0);

    if(pos) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}


Compiler output:
a.cc: In function 'll dfs(int)':
a.cc:34:9: error: expected ',' or ';' before 'return'
   34 |         return ret;
      |         ^~~~~~
Language: C++

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
using namespace std;
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int n;
LL a[100005];
LL Have[100005];
vector < int > E[100005];

void yes(){
	cout << "YES" << endl;
	exit(0);
}

void no(){
	cout << "NO" << endl;
	exit(0);
}

void dfs( int u , int p ){
	Have[u] = 0;

	if ( E[u].size() == 1 ){
		Have[u] = a[u];
		return;
	}

	if ( p == -1 ){
		vector < LL > val;
		for ( int v : E[u] ){
			dfs(v,u);
			val.pb(Have[v]);
		}
		sort(val.begin(),val.end());

		LL sum = 0;
		LL fsum = 0;
		LL target = a[u];
		for ( LL v : val ){
			sum += v;
		}
		for ( int i = 0; i < val.size(); i++ ){
			LL v = val[i];
			if ( fsum <= target && fsum + v >= target ){
				LL l = 0, r = v;
				while ( l < r){
					LL m = ( l + r ) / 2;
					if ( fsum + m >= target ) r = m;
					else l = m + 1;
				}
				fsum += l;
				sum -= l;
				if ( fsum >= target && sum >= target ){
					yes();
				} else {
					no();
				}
			}

			fsum += v;
			sum -= v;
			if ( fsum >= target ){
				if ( sum >= target ){
					yes();
				}
				no();
			}
			if ( sum < target ){
				no();
			}
		}
	} else {
		for ( int v : E[u] ){
			if ( v == p ) continue;
			dfs(v,u);
			Have[u] += Have[v];
		}

		if ( Have[u] < a[u] ){
			no();
		}
		Have[u] = a[u];
	}
}

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	for ( int i = 1; i <= n; i++ ) cin >> a[i];

	for ( int i = 0; i < n-1; i++ ){
		int u , v;
		cin >> u >> v;
		E[u].pb(v);
		E[v].pb(u);
	}

	if ( n == 2 ){
		yes();
	}

	for ( int i = 1; i <= n; i++ ){
		if ( E[i].size() == 1 ) continue;
		dfs(i,-1);
		assert(1==2);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:119:17: error: 'assert' was not declared in this scope
  119 |                 assert(1==2);
      |                 ^~~~~~
a.cc:8:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    7 | #include <set>
  +++ |+#include <cassert>
    8 | using namespace std;
Language: C++

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int main() {
	int n;
	scanf("%d",&n);
	fup(i,1,n,1)scanf("%lld",a+i);
	fup(i,1,n-1,1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	fup(i,1,n,1)
	{
		if(v[i].size()>1)
		{
			ll sum=0;
			for(int next:v[i])
			{
				sum+=a[next];
			}
			if(sum&1)return !printf("NO");
			for(int next:v[i])
			{
				if(a[next]>sum/2)return !printf("NO");
			}
		}
	}
	puts("YES");
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:34: error: 'a' was not declared in this scope
   65 |         fup(i,1,n,1)scanf("%lld",a+i);
      |                                  ^
a.cc:70:17: error: 'v' was not declared in this scope
   70 |                 v[x].pb(y);
      |                 ^
a.cc:75:20: error: 'v' was not declared in this scope
   75 |                 if(v[i].size()>1)
      |                    ^
a.cc:80:38: error: 'a' was not declared in this scope
   80 |                                 sum+=a[next];
      |                                      ^
a.cc:85:36: error: 'a' was not declared in this scope
   85 |                                 if(a[next]>sum/2)return !printf("NO");
      |                                    ^
Language: C++

#include <bits/stdc++.h>

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
using namespace std;

signed main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<vector<int>> g(N, vector<int>());
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  auto dfs = [&](auto&& f, int p, int x, int& r) {
    vector<int> l;
    int t;
    r = A[x];
    int sum = 0;
    for (auto a : g[x]) {
      if (a == p) continue;
      if (!f(f, x, a, t)) return false;
      l.push_back(t);
      sum += t;
    }
    sort(l.begin(), l.end());
    if (l.size() == 0) return true;
    int mi = sum - min(sum / 2, (sum - l.back()));
    r = 2 * A[x] - sum;
    return mi <= A[x] && A[x] <= sum;
  };
  int res;
  if (dfs(dfs, -1, 0, res)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Compiler output:
a.cc: In instantiation of 'main()::<lambda(auto:28&&, long long int, long long int, long long int&)> [with auto:28 = main()::<lambda(auto:28&&, long long int, long long int, long long int&)>&]':
a.cc:39:10:   required from here
   39 |   if (dfs(dfs, -1, 0, res)) cout << "YES" << endl;
      |       ~~~^~~~~~~~~~~~~~~~~
a.cc:28:13: error: use of 'main()::<lambda(auto:28&&, long long int, long long int, long long int&)> [with auto:28 = main()::<lambda(auto:28&&, long long int, long long int, long long int&)>&]' before deduction of 'auto'
   28 |       if (!f(f, x, a, t)) return false;
      |            ~^~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
using namespace std;

signed main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<vector<int>> g(N, vector<int>());
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  auto dfs = [&](auto f, int p, int x, int& r) {
    vector<int> l;
    int t;
    r = A[x];
    int sum = 0;
    for (auto a : g[x]) {
      if (a == p) continue;
      if (!f(f, x, a, t)) return false;
      l.push_back(t);
      sum += t;
    }
    sort(l.begin(), l.end());
    if (l.size() == 0) return true;
    int mi = sum - min(sum / 2, (sum - l.back()));
    r = 2 * A[x] - sum;
    return mi <= A[x] && A[x] <= sum;
  };
  int res;
  if (dfs(dfs, -1, 0, res)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Compiler output:
a.cc: In instantiation of 'main()::<lambda(auto:28, long long int, long long int, long long int&)> [with auto:28 = main()::<lambda(auto:28, long long int, long long int, long long int&)>]':
a.cc:39:10:   required from here
   39 |   if (dfs(dfs, -1, 0, res)) cout << "YES" << endl;
      |       ~~~^~~~~~~~~~~~~~~~~
a.cc:28:13: error: use of 'main()::<lambda(auto:28, long long int, long long int, long long int&)> [with auto:28 = main()::<lambda(auto:28, long long int, long long int, long long int&)>]' before deduction of 'auto'
   28 |       if (!f(f, x, a, t)) return false;
      |            ~^~~~~~~~~~~~
Language: C++

#include<stdio.h>
#include<bits/locale_facets.h>
#include<memory.h>
#include<math.h>
using namespace std;
const int nn=100001;
int A[nn],degree[nn],time[nn];
long long input();
void output(long long value);
template<int nodes>struct phylogenetic_tree
{
	int root,total,t,memory,other,father[nodes],son[nodes],depth[nodes],last[nodes],next[nodes];
	phylogenetic_tree()
	{
		other=nodes*4,t=log(nodes)/log(2);
		clear();
	}
	void clear()
	{
		memset(son,0,4*(total+1));
		memset(father,0,other);
		memset(last,0,other);
		memset(depth,0,other);
		root=total=0;
	}
	void insert(int f,int s)
	{
		if(father[s])return ;
		if(!root)root=f;
		else if(!father[f])return ;
		father[s]=f,son[++total]=s;
		next[total]=last[f],last[f]=total;
	}
	int new1(int p,int from)
	{
		if(degree[p]==1)return time[from]=A[p];
		int sum=0;
		for(int i=last[p];i;i=next[i])
		if((i>>1)!=from)sum+=new1(son[i],i>>1);
		if(sum>A[p]<<1)printf("NO"),exit(0);
		if(!from)
		{
			if(sum==A[p]<<1)printf("YES");
			else printf("NO");
			exit(0);
		}
		return time[from]=(A[p]<<1)-sum;
	}
};
phylogenetic_tree<nn>stone;
int main()
{
	stone.total=1;
	int n=input(),a,b;
	for(int i=1;i<=n;i++)A[i]=input();
	for(int i=1;i<n;i++)
	{
		a=input(),b=input();
		stone.insert(a,b),stone.insert(b,a);
		degree[a]++,degree[b]++;
	}
	for(int i=1;i<=n;i++)
	if(degree[i]>1)stone.new1(i,0);
}
long long input()
{
	long long value=0,positive=1;
	char digit=getchar();
	for(;!isdigit(digit);digit=getchar())
	if(digit=='-')positive=-positive;
	for(;isdigit(digit);digit=getchar())value=(value<<3)+(value<<1)+digit-'0';
	return positive*value;
}
void output(long long value)
{
	if(value<0)
	{
		putchar('-');
		value=-value;
	}
	if(value>=10)output(value/10);
	putchar(value%10+'0');
}

Compiler output:
a.cc:7:29: error: 'int time [100001]' redeclared as different kind of entity
    7 | int A[nn],degree[nn],time[nn];
      |                             ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/bits/locale_facets.h:43,
                 from a.cc:2:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In member function 'int phylogenetic_tree<nodes>::new1(int, int)':
a.cc:36:50: error: assignment of read-only location 'time[from]'
   36 |                 if(degree[p]==1)return time[from]=A[p];
      |                                        ~~~~~~~~~~^~~~~
a.cc:47:34: error: assignment of read-only location 'time[from]'
   47 |                 return time[from]=(A[p]<<1)-sum;
      |                        ~~~~~~~~~~^~~~~~~~~~~~~~
Language: C++

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

int n;
long long a[100010];
bool visited[100010] = {};

vector<int> graph[100010];

long long dfs(int idx){
    visited[idx] = true;

    priority_queue<long long> que;

    long long line = 0;
    for(int i = 0;i < graph[idx].size();i++){
        if(!visited[graph[idx][i]]){
            long long tmp = dfs(graph[idx][i]);
            que.push(tmp);
            line += tmp;
        }
    }

    if(que.empty()){
        return a[idx];
    }

    long long ok = line - a[idx];
    if(ok < 0){
        cout <<"NO" << endl;
        exit(0);
    }

    long long cnt = 0;
    while(que.size() > 1){
        long long tmp = que.top();
        que.pop();
        long long tmp2 = que.top();
        cnt += que.top();
        que.pop();
        que.push(tmp-tmp2);
    }

    if(ok <= cnt){
        return a[idx]-ok;
    }else{
        cout << "NO" << endl;
        exit(0);
    }
}

int main(){
    cin >> n;
    int s, t;

    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    for(int i = 0;i < n-1;i++){
        cin >> s >> t;
        s--; t--;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }

    int ta[100010] = {};

    int root = 0;

    while(1){
        int i;
        ta[root] = 1;
        for(i = 0;i < graph[root].size();i++){
            if(ta[graph[root][i]] == 0){
                root = graph[root][i];
                break;
            }
        }
        if(i == graph[root].size()){
            break;
        }
    }

    dfs(root);
    cout << "YES" << endl;

    return 0;
}






someha@DESKTOP-UG27

Compiler output:
a.cc:96:7: error: stray '@' in program
   96 | someha@DESKTOP-UG27
      |       ^
a.cc:96:1: error: 'someha' does not name a type
   96 | someha@DESKTOP-UG27
      | ^~~~~~
Language: C++

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

int n;
long long a[100010];
bool visited[100010] = {};

vector<int> graph[100010];

long long dfs(int idx){
    visited[idx] = true;

    priority_queue<long long> que;

    long long line = 0;
    for(int i = 0;i < graph[idx].size();i++){
        if(!visited[graph[idx][i]]){
            long long tmp = dfs(graph[idx][i]);
            que.push(tmp);
            line += tmp;
        }
    }

    if(que.empty()){
        return a[idx];
    }

    long long ok = line - a[idx];

    long long cnt = 0;
    while(que.size() > 1){
        long long tmp = que.top();
        que.pop();
        long long tmp2 = que.top();
        cnt += que.top();
        que.pop();
        que.push(tmp-tmp2);
    }

    if(ok <= cnt){
        return a[idx]-ok;
    }else{
        cout << "NO" << endl;
        exit(0);
    }
}

int main(){
    cin >> n;
    int s, t;

    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    for(int i = 0;i < n-1;i++){
        cin >> s >> t;
        s--; t--;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }

    int ta[100010] == {};

    int root = 0;

    while(1){
        int i;
        ta[root] = 1;
        for(i = 0;i < graph[root].size();i++){
            if(ta[graph[root][i]] == 0){
                root = graph[root][i];
                break;
            }
        }
        if(i == graph[root].size()){
            break;
        }
    }

    dfs(root);
    cout << "YES" << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:63:20: error: expected initializer before '==' token
   63 |     int ta[100010] == {};
      |                    ^~
a.cc:69:9: error: 'ta' was not declared in this scope; did you mean 't'?
   69 |         ta[root] = 1;
      |         ^~
      |         t
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long

myMake(int cur, vector<vector<int> > &adj, vector<vector<int> > &G, vector<bool> &used){

    used[cur] = true;
    for(auto nxt : adj[cur]){
        if(used[nxt]) continue;
        G[cur].push_back(nxt);
        myMake(nxt, adj, G, used);
    }
}

int dfs(int cur, vector<vector<int> > &G, vector<int> &A){

    if(G[cur].size() == 0){
        cerr << cur << " " << A[cur] << endl;
        return A[cur];
    }

    int sum = 0;
    
    vector<int> vec;    
    for(auto nxt : G[cur]){
        int val = dfs(nxt, G, A);
        if(val < 0){
            cerr << cur << " " << -1 << endl;
            return -1;
        }
        vec.push_back(val);
        sum += val;
    }

    int ret = 2 * A[cur] - sum;
    //cout << cur << " " << sum << " " << A[cur] << " " << ret << endl;
    if(ret < 0){
        cerr << cur << " " << -1 << endl;
        return -1;
    }

    vec.push_back(ret);

    int n = (int)vec.size();
    sum += ret;
    assert(sum % 2 == 0);

    bool ok = true;
    for(int i = 0; i < n; i++){
        if(vec[i] > sum / 2){
            cerr << cur << " " << -1 << endl;            
            return -1;
        }
    }

    cerr << cur << " " << ret << endl;
    return ret;
}

signed main(){

    int N; cin >> N;
    vector<int> A(N);
    vector<vector<int> > adj(N); // {node}
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N - 1; i++){
        int a, b; cin >> a >> b; a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    vector<bool> used(N, false);
    vector<vector<int> > G(N);  // 0 を根とする 根付き木

    
    myMake(0, adj, G, used);    

    int val = (G[0].size() == 1 ? A[0] : 0);
    if(dfs(0, G, A) == val) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Compiler output:
a.cc:5:1: error: ISO C++ forbids declaration of 'myMake' with no type [-fpermissive]
    5 | myMake(int cur, vector<vector<int> > &adj, vector<vector<int> > &G, vector<bool> &used){
      | ^~~~~~
a.cc: In function 'int myMake(long long int, std::vector<std::vector<long long int> >&, std::vector<std::vector<long long int> >&, std::vector<bool>&)':
a.cc:13:1: warning: no return statement in function returning non-void [-Wreturn-type]
   13 | }
      | ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long

make(int cur, vector<vector<int> > &adj, vector<vector<int> > &G, vector<bool> &used){

    used[cur] = true;
    for(auto nxt : adj[cur]){
        if(used[nxt]) continue;
        G[cur].push_back(nxt);
        make(nxt, adj, G, used);
    }
}

int dfs(int cur, vector<vector<int> > &G, vector<int> &A){

    if(G[cur].size() == 0){
        cerr << cur << " " << A[cur] << endl;
        return A[cur];
    }

    int sum = 0;
    
    vector<int> vec;    
    for(auto nxt : G[cur]){
        int val = dfs(nxt, G, A);
        if(val < 0){
            cerr << cur << " " << -1 << endl;
            return -1;
        }
        vec.push_back(val);
        sum += val;
    }

    int ret = 2 * A[cur] - sum;
    //cout << cur << " " << sum << " " << A[cur] << " " << ret << endl;
    if(ret < 0){
        cerr << cur << " " << -1 << endl;
        return -1;
    }

    vec.push_back(ret);

    int n = (int)vec.size();
    sum += ret;
    assert(sum % 2 == 0);

    bool ok = true;
    for(int i = 0; i < n; i++){
        if(vec[i] > sum / 2){
            cerr << cur << " " << -1 << endl;            
            return -1;
        }
    }

    cerr << cur << " " << ret << endl;
    return ret;
}

signed main(){

    int N; cin >> N;
    vector<int> A(N);
    vector<vector<int> > adj(N); // {node}
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N - 1; i++){
        int a, b; cin >> a >> b; a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    vector<bool> used(N, false);
    vector<vector<int> > G(N);  // 0 を根とする 根付き木

    
    make(0, adj, G, used);    

    int val = (G[0].size() == 1 ? A[0] : 0);
    if(dfs(0, G, A) == val) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Compiler output:
a.cc:5:1: error: ISO C++ forbids declaration of 'make' with no type [-fpermissive]
    5 | make(int cur, vector<vector<int> > &adj, vector<vector<int> > &G, vector<bool> &used){
      | ^~~~
a.cc: In function 'int make(long long int, std::vector<std::vector<long long int> >&, std::vector<std::vector<long long int> >&, std::vector<bool>&)':
a.cc:13:1: warning: no return statement in function returning non-void [-Wreturn-type]
   13 | }
      | ^
Language: C++

#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 100100
#define ll long long
inline int read()
{
    int x=0;bool t=false;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=true,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return t?-x:x;
}
void WA(){puts("NO");exit(0);}
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1,dg[MAX];
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;++dg[u];}
int n,a[MAX],rt;
void dfs(int u,int ff)
{
    int mx=0;ll sum=0;
    for(int i=h[u];i;i=e[i].next)
    {
        int v=e[i].v;if(v==ff)continue;
        dfs(v,u);mx=max(mx,a[v]);sum+=a[v];
    }
    if(dg[u]==1)return;
    ll mn=min(sum/2,min(1ll*mx,sum-mx));
    if(a[u]>sum)WA();
    else
    {
        if(sum-mn>a[u])WA();
        else a[u]-=sum-a[u];
    }
}
int main()
{
    n=read();
    for(int i=1;i<=n;++i)a[i]=read();
    if(n==2){puts(a[1]==a[2]?"YES":"NO");return 0;}
    for(int i=1;i<n;++i)
    {
        int u=read(),v=read();
        Add(u,v);Add(v,u);
    }
    for(int i=1;i<=n;++i)
        if(dg[i]>1){dfs(rt=i,0);break;}
    if(a[rt])WA();else puts("YES");
    sreturn 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:5: error: 'sreturn' was not declared in this scope
   49 |     sreturn 0;
      |     ^~~~~~~
Language: C++

#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 100100
#define ll long long
inline int read()
{
    int x=0;bool t=false;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=true,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return t?-x:x;
}
void WA(){puts("NO");exit(0);}
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1,dg[MAX];
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;++dg[u];}
int n,a[MAX],rt;
void dfs(int u,int ff)
{
    int mx=0;ll sum=0;
    for(int i=h[u];i;i=e[i].next)
    {
        int v=e[i].v;if(v==ff)continue;
        dfs(v,u);mx=max(mx,a[v]);sum+=a[v];
    }
    if(dg[u]==1)return;
    ll mn=min(sum/2,min(mx,sum-mx));
    if(a[u]>sum)WA();
    else
    {
        if(sum-mn>a[u])WA();
        else a[u]-=sum-a[u];
    }
}
int main()
{
    n=read();
    for(int i=1;i<=n;++i)a[i]=read();
    if(n==2){puts(a[1]==a[2]?"YES":"NO");return 0;}
    for(int i=1;i<n;++i)
    {
        int u=read(),v=read();
        Add(u,v);Add(v,u);
    }
    for(int i=1;i<=n;++i)
        if(dg[i]>1){dfs(rt=i,0);break;}
    if(a[rt])WA();else puts("YES");
    sreturn 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:28:24: error: no matching function for call to 'min(int&, long long int)'
   28 |     ll mn=min(sum/2,min(mx,sum-mx));
      |                     ~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:28:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   28 |     ll mn=min(sum/2,min(mx,sum-mx));
      |                     ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
a.cc: In function 'int main()':
a.cc:49:5: error: 'sreturn' was not declared in this scope
   49 |     sreturn 0;
      |     ^~~~~~~
Language: C++

#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
LL A[114514];
vector<int> es[114514];

pair<LL, LL> dfs(int v, int p) {
  int num_ch = 0;
  LL l = 0;
  LL r = 0;
  LL s = 0;
  LL ls = 0;
  LL maxa = -1;
  LL maxb = -1;
  for (int u : es[v]) {
    if (p == u) continue;
    LL x, y;
    tie(x, y) = dfs(u, v);
    s += y;
    ls += x;
    maxa = max(maxa, x);
    maxb = max(maxb, y);
    LL nr = y+r;
    LL nl = max(0LL, max(x, l) - min(y, r));
    l = nl;
    r = nr;
    num_ch++;
  }

  if (ls/2 + ls%2 > A[v]) {
    puts("NO");
    exit(0);
  }

  LL mp = 0;
  if (2*maxa > s) mp = s-maxa;

  LL mp2 = s/2;
  if (2*maxb > s) mp2 = s - maxb;
  mp2 = A[v] - mp2;

  if (num_ch == 0) return make_pair(A[v], A[v]);
  if (num_ch == 1) {
    if (l <= A[v] && A[v] <= r) return make_pair(A[v], A[v]);
    puts("NO");
    exit(0);
  }
  return make_pair(max(l, max(mp2, mp)), min(r, A[v]));
}

int main() {
  scanf("%d", &N);
  rep(i, N) {
    scanf("%lld", &A[i]);
  }

  rep(i, N-1) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    es[u].eb(v);
    es[v].eb(u);
  }

  rep(v, N) {
    if (es[v].size() > 1) {
      cnt++;
      if (dfs(v, v).first != 0) {
        puts("NO");
        exit(0);
      }

      if (cnt > 3) {
        puts("YES");
        exit(0);
      }
    }
  }

  assert(N == 2);
  if (A[0] == A[1]) puts("YES");
  else puts("NO");
}


Compiler output:
a.cc: In function 'int main()':
a.cc:93:7: error: 'cnt' was not declared in this scope; did you mean 'int'?
   93 |       cnt++;
      |       ^~~
      |       int
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
vector<int> G[100010];
ll a[100010];
bool ans;
void dfs(int v,int p){
	ll sum=0;
	ll ma=0;
	if(G[v].size()==1)return;
	for(auto e:G[v]){
		if(e==p)continue;
		dfs(e,v);
		sum+=a[e];
		ma=max(ma,a[e]);
	}
	if(a[v]>sum){
		ans=false;
	}else if(a[v]<sum){
		if(ma>a[v]){
			ans=false;
		}
		if((sum-a[v])*2LL>sum){
			ans=false;
		}else{
			a[v]=sum-(sum-a[v])*2LL;
		}
	}
}
int main(){
	ans=true;
	int n;cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];]
	}
	if(n==2){
		if(a[0]!=a[1]){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		}
		return 0;
	}
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int v;
	for(int i=0;i<n;i++){
		if(G[i].size()!=1){
			v=i;
			break;
		}
	}
	dfs(v,-1);
	if(a[v])ans=false;
	if(ans){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:27: error: expected primary-expression before ']' token
   43 |                 cin>>a[i];]
      |                           ^
Language: C++

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

const int N = 1e5 + 5;
const int M = N * 2;

int fir[N] , ne[M] , to[M] , cnt , dp[N] , n , m  , x , y , du[N]  , A[N] , fa[N];

void add(int x , int y) {
  ne[++ cnt] = fir[x];
  fir[x] = cnt;
  to[cnt] = y;
  ++ du[x];
}

void link(int x , int y) {
  add(x , y);
  add(y , x);
}

#define Foreachson(i , x) for(int i = fir[x];i;i = ne[i])

void dfs(int x , int f) {
  fa[x] = f;
  Foreachson(i , x) {
    int V = to[i];
    if(V == f) continue;
    A[x] -= A[V];
    dfs(V , x);
  }
}

#define Cannot exit(puts("NO") * 0)

void calc(int x , int f) {
  if(du[x] == 1) {
    dp[x] = A[x];
    return;
  }
  int now = 0 , Max = 0;
  Foreachson(i , x) {
    int V = to[i];
    if(V == f) continue;
    calc(V , x);
    now += dp[V]; Max = max(Max , dp[V]);
  }
  if(now >= (-A[x]) * 2 && now - Max >= (-A[x])) {
    dp[x] = now + cxt.back() + A[x] * 2; A[fa[x]] -= A[x];
  }
  else Cannot;
}

int main() {
  scanf("%d" , &n);
  for(int i = 1;i <= n;++ i)
    scanf("%d" , &A[i]);
  for(int i = 1;i < n;++ i) {
    scanf("%d%d" , &x , &y);
    link(x , y);
  }
  if(n == 2) {
    if(A[1] == A[2]) puts("YES"); else Cannot;
    return 0;
  }
  int rt = 0;
  for(int i = 1;i <= n;++ i) {
    if(du[i] >= 2) {
      dfs(i , 0);
      calc(i , 0);
      if(dp[i]) Cannot;
      puts("YES");
      return 0;
    }
  }
}

Compiler output:
a.cc: In function 'void calc(int, int)':
a.cc:48:19: error: 'cxt' was not declared in this scope; did you mean 'cnt'?
   48 |     dp[x] = now + cxt.back() + A[x] * 2; A[fa[x]] -= A[x];
      |                   ^~~
      |                   cnt
Language: C++

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

vector<int32> G[112345];
int32 N;
vector<int64> A;

int64 dfs(int32 v, int32 p){
	if(G[v].size() == (p != -1)) return A[v];
	vector<int64> c;
	REP(i, G[v].size()){
		if(G[v][i] == p) continue;
		c.push_back(dfs(G[v][i], v));
		sum += c[c.size()-1];
		if(c[c.size()-1] == -1) return -1;
	}
	sort(all(c), greater<int64>());
	int32 x = 2*A[v]-sum;
	if((sum-x)%2) return -1;
	if((sum-x)/2 <= min(c[0], sum/2)) return x;
	return -1;
}

int main(void){
	cin >> N;
	A.resize(N);
	REP(i, N) cin >> A[i];
	REP(i, N-1){
		int32 a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if(dfs(0, -1) == -1) cout << "NO" << endl;
	else cout << "YES" << endl;
}

Compiler output:
a.cc: In function 'int64 dfs(int32, int32)':
a.cc:36:17: error: 'sum' was not declared in this scope
   36 |                 sum += c[c.size()-1];
      |                 ^~~
a.cc:40:26: error: 'sum' was not declared in this scope
   40 |         int32 x = 2*A[v]-sum;
      |                          ^~~
Language: C++

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn=1e5+10,mod=1e9+7;
    int n,m,k,t,a[maxn],rt;
    vector<int>e[maxn];
    bool flag=true;
    long long dfs(int x,int y=0)
    {
        if(!flag)return -1;
        if(e[x].size()==1)return a[x];
        long long sum=0;
        vector<long long>tmp;
        for(int i=0;i<e[x].size();i++)
        {
            int z=e[x][i];
            if(z==y)continue;
            long long j=dfs(z,x);
            if(j>a[x])
           {
                flag=false;
                return;
           }
            if(j==-1)return -1;
            tmp.push_back(j);
            sum+=j;
        }
        long long delta=(sum-a[x]),ans=sum-2*delta;
        if( ans <0 || delta <0)
        {
            flag=false;
            return -1;
        }
        sort(tmp.begin(),tmp.end());
        int pos=tmp.size()-1;
        if(x==rt&&ans>0)
        {
            flag=false;
        }
        return ans;
    }
    int main(){
        int i,j;
        scanf("%d",&n);
        for(i=1;i<=n;i++)scanf("%d",&a[i]);
        for(i=1;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            e[x].push_back(y);
            e[y].push_back(x);
        }
        if(n==2)
        {
            if(a[1]==a[2])puts("YES");
            else puts("NO");
            return 0;
        }
        for(i=1;i<=n;i++)if(e[i].size()>1)
        {
            rt=i;
            dfs(rt);
            break;
        }
        puts(flag?"YES":"NO");
        return 0;
    }

Compiler output:
a.cc: In function 'long long int dfs(int, int)':
a.cc:21:17: error: return-statement with no value, in function returning 'long long int' [-fpermissive]
   21 |                 return;
      |                 ^~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10,mod=1e9+7;
int n,m,k,t,a[maxn],rt;
vector<int>e[maxn];
bool flag=true;
long long dfs(int x,int y=0)
{
    if(!flag)return -1;
    if(e[x].size()==1)return a[x];
    long long sum=0;
    vector<long long>tmp;
    for(int i=0;i<e[x].size();i++)
    {
        int z=e[x][i];
        if(z==y)continue;
        long long j=dfs(z,x);
        if(j>a[x])
       {
            flag=false;
            return;
       }
        if(j==-1)return -1;
        tmp.push_back(j);
        sum+=j;
    }
    long long delta=(sum-a[x]),ans=sum-2*delta;
    if( ans <0 || delta <0)
    {
        flag=false;
        return -1;
    }
    sort(tmp.begin(),tmp.end());
    int pos=tmp.size()-1;
    for(int i=0;i<pos;)
    {
        if(!delta)break;
        long long p=min(min(delta,tmp[i]),tmp[pos]);
        tmp[i]-=p;
        tmp[pos]-=p;
        delta-=p;
        if(!delta)break;
        if(tmp[pos]==0)pos--;
        else i++;
    }
    if(delta)
    {
        flag=false;
    }
    if(x==rt&&ans>0)
    {
        flag=false;
    }
    return ans;
}
int main(){
    int i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    for(i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    if(n==2)
    {
        if(a[1]==a[2])puts("YES");
        else puts("NO");
        return 0;
    }
    for(i=1;i<=n;i++)if(e[i].size()>1)
    {
        rt=i;
        dfs(rt);
        break;
    }
    puts(flag?"YES":"NO");
    return 0;
}

Compiler output:
a.cc: In function 'long long int dfs(int, int)':
a.cc:21:13: error: return-statement with no value, in function returning 'long long int' [-fpermissive]
   21 |             return;
      |             ^~~~~~
Language: C++

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 100005

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;
int A[110000];
vector<int>g[110000];
bool dame=false;
long long dfs(int a,int b){
	long long rem=c[a];
	if(g[a].size()>1)rem*=2;
	for(int i=0;i<g[a].size();i++){
		if(b==g[a][i])continue;
		long long v=dfs(g[a][i],a);
		if(v>c[a])dame=true;
		rem-=v;
	}
	if(rem>c[a])dame=true;
	if(rem<0)dame=true;
	if(b==-1&&rem)dame=true;
	return rem;
}
int main(){
	int N;cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N-1;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	if(N==2){
		if(c[0]==c[1])cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		return 0;
	}
	int at=-1;
	for(int i=0;i<N;i++){
		if(g[i].size()>1){
			at=i;break;
		}
	}
	if(at==-1)return 1;
	dfs(at,-1);
	if(dame)printf("NO\n");else printf("YES\n");
}


Compiler output:
a.cc: In function 'long long int dfs(int, int)':
a.cc:49:23: error: 'c' was not declared in this scope
   49 |         long long rem=c[a];
      |                       ^
a.cc: In function 'int main()':
a.cc:71:20: error: 'c' was not declared in this scope
   71 |                 if(c[0]==c[1])cout<<"YES"<<endl;
      |                    ^
Language: C++

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct edge
{
    int y;
    edge * next;
};
edge * li[100005];
edge * new_edge()
{
    static edge a[200005];
    static int top=0;
    return &a[top++];
}
void inserts(int x,int y)
{
    edge * t=new_edge();
    t->next=li[x];
    t->y=y;
    li[x]=t;
}
void insert_edge(int x,int y)
{
    inserts(x,y);
    inserts(y,x);
}
long long val[100005];
long long tag[100005];
int deg[100005];
int fa[100005];
void dfs(int x)
{
    edge * t;
    int sum=0;
    for (t=li[x];t!=0;t=t->next)
    {
        if (t->y==fa[x]) continue;
        fa[t->y]=x;
        dfs(t->y);
        if (def[t->y]>1) val[x]-=val[t->y]*2;
        sum++;
    }
    if (sum==0)
    {
        tag[x]=val[x];
    }
    if (fa[x]!=-1)
    {
        tag[fa[x]]+=tag[x];
    }
    if (sum!=0)
    {
        val[x]-=tag[x];
    }
    tag[x]=0;
}
int res=0;
void dfs2(int x)
{
    edge * t;
    int sum=0;
    long long sum_val=0;
    long long max_val=0;
    for (t=li[x];t!=0;t=t->next)
    {
        if (t->y==fa[x]) continue;
        dfs2(t->y);
        sum++;
        sum_val+=tag[t->y];
        max_val=max(max_val,tag[t->y]);
    }
    if (sum==0)
    {
        tag[x]=val[x];
        return;
    }
    if (val[x]>0)
    {
        res=-1;
    }
    if (val[x]+(sum_val-max_val)<0)
    {
        res=-1;
    }
    if (val[x]+(sum_val/2)<0)
    {
        res=-1;
    }
    sum_val+=val[x]*2;
    tag[x]=sum_val;
    return;
}
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        int t;
        scanf("%d",&t);
        val[i]=t;
    }
    int root=-1;
    for (i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x--;
        y--;
        deg[x]++;
        deg[y]++;
        if (deg[x]>=2) root=x;
        if (deg[y]>=2) root=y;
        insert_edge(x,y);
    }
    if (n==2)
    {
        if (val[0]==val[1])
        {
            puts("YES");
        }
        else
        {
            puts("NO");
        }
        return 0;
    }
    fa[root]=-1;
    dfs(root);
    dfs2(root);
    if (tag[root]!=0) res=-1;
    if (res==-1)
    {
        puts("NO");
    }
    else
    {
        puts("YES");
    }
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:58:13: error: 'def' was not declared in this scope; did you mean 'deg'?
   58 |         if (def[t->y]>1) val[x]-=val[t->y]*2;
      |             ^~~
      |             deg
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(ll (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
const ll maxn=1e5+5;
ll n,tot,flag,rt;
ll d[maxn],a[maxn],head[maxn],des[maxn<<1],nxt[maxn<<1];
void adde(ll x,ll y){
	des[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
ll dfs(ll x,ll fa){
	ll can=0,rest=0,tot=0,cnt=0;
	vector<ll>q;
	Rep(p,x)if(des[p]!=fa)q.pb(dfs(des[p],x));
	sort(All(q));reverse(All(q));
	rep2(i,0,SZ(q))can+=min(q[i],rest),rest=rest+q[i]-2*min(q[i],rest),tot+=q[i],cnt++;
	if(!cnt)return a[x];
	if(x!=rt){
		ll need=tot-a[x];
		if(need<0||can<need)flag=1;
		return tot-2*need;
	}else{
		if(rest||can!=a[x])flag=1;
	}
}
ll main(){
	read(n);
	rep(i,1,n)read(a[i]);
	rep(i,1,n-1){
		ll x,y;read(x);read(y);
		adde(x,y);adde(y,x);
		d[x]++;d[y]++;
	}
	if(n==2){
		if(a[1]==a[2])puts("YES");
		else puts("NO");
		return 0;
	}
	rep(i,1,n)if(d[i]>1)rt=i;
	dfs(rt,0);
	if(flag)puts("NO");
	else puts("YES");
	return 0;
}

Compiler output:
a.cc:44:1: error: '::main' must return 'int'
   44 | ll main(){
      | ^~
a.cc: In function 'll dfs(ll, ll)':
a.cc:43:1: warning: control reaches end of non-void function [-Wreturn-type]
   43 | }
      | ^
Language: C++

#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> PL;

const int N = 123456;
ll a[N];
VI edges[N];


ll dfs(int v, int par) {
  vector<ll> pool;
  ll tot = 0;
  rep(i, edges[v].size()) {
    int w = edges[v][i];
    if (w == par) { continue; }
    ll sub = dfs(w, v);
    if (sub < 0) {
      return -1;
    }
    pool.push_back(sub);
    tot += sub;
  }
  ll rest = 0;
  if (par == -1) {
    if (pool.size() >= 2 && tot != 2 * a[v]) {
      return -1;
    }
    if (pool.size() == 1 && tot != a[v]) {
      return -1;
    }
  } else {
    rest = pool.size() >= 1 ? 2 * a[v] - tot : a[v];
    if (rest < 0) {
      return -1;
    }
    pool.push_back(rest);
  }
  sort(pool.rbegin(), pool.rend());
  if (pool.size() >= 2 && pool[0] > a[v]) {
    return -1;
  }
  if (pool.size() == 1) {
    if (pool[0] != a[v]) {
      return -1;
    }
    return a[v];
  }
  return rest;
}

int main(void) {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  ll result = dfs(0, -1);
  cout << (result >= 0 ? "YES" : "NO") << endl;
}


Compiler output:
a.cc: In function 'll dfs(int, int)':
a.cc:45:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   45 |   sort(pool.rbegin(), pool.rend());
      |   ^~~~
      |   short