Language: C++

/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

#define MAXN 100000
void [[noreturn]] out(int t=0) 
{
	debug(t);
	puts("NO");
	exit(0);
}
LL a[MAXN+10];	
struct Edge
{
	int to,next;
}e[2*MAXN+10];
int head[MAXN+10];
void addEdge(int a,int b)
{
	static int c=0;
	e[++c]=(Edge){b,head[a]};
	head[a]=c;
	e[++c]=(Edge){a,head[b]};
	head[b]=c;
}
LL dp(int now,int fa)
{
	LL sum=0;
	int mx=0;
	for(int i=head[now]; i!=0; i=e[i].next) {
		int v=e[i].to;
		if (v==fa) continue;
		LL son=dp(v,now);
		mx=max(mx,son);
		sum+=son;
	}
	if (mx==0) return a[now];
	//debug(now,a[now],sum);
	if (a[now]>sum || sum>2*a[now]) out(1);
	LL t=sum-a[now];
	if ((sum-mx)<t) out(2);
	return 2*a[now]-sum;
}
int main(){	
#ifdef WAAUTOMATON	
	freopen("in.txt","r",stdin);
#endif
	int n;
	cin>>n;
	for(int i=1; i<=n; ++i) {
		cin>>a[i];
	}
	for(int i=1; i<n; ++i) {
		int x,y;
		cin>>x>>y;
		addEdge(x,y);
	}
	LL x=dp(1,0);
	//if (x!=a[1]) out(3);
	puts("YES");
	return 0;
}


Compiler output:
a.cc:30:6: warning: attribute ignored [-Wattributes]
   30 | void [[noreturn]] out(int t=0)
      |      ^
a.cc:30:6: note: an attribute that appertains to a type-specifier is ignored
a.cc: In function 'LL dp(int, int)':
a.cc:58:23: error: no matching function for call to 'max(int&, LL&)'
   58 |                 mx=max(mx,son);
      |                    ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:58:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'LL' {aka 'long long int'})
   58 |                 mx=max(mx,son);
      |                    ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:58:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   58 |                 mx=max(mx,son);
      |                    ~~~^~~~~~~~