Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)&&ch!='-')
		ch=getchar();
	if (ch=='-')
		f=-1,ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
const int N=100005;
int n,A[N],in[N];
vector <int> e[N];
vector <LL> v[N];
LL solve(int x,int pre){
	vector <LL> &a=v[x];
	for (auto y : e[x])
		if (y!=pre)
			a.push_back(solve(y,x));
	if (a.empty())
		return A[x];
	sort(a.begin(),a.end());
	if (!~*a.begin())
		return -1;
	reverse(a.begin(),a.end());
	LL tot=0;
	for (auto y : a)
		tot+=y;
	LL mx=min((LL)A[x],min(*a.begin(),tot-*a.begin()));
	LL Need=tot-A[x];
	return Need>mx?-1:(A[x]-Need);
}
int main(){
	srand('C'+'L'+'Y'+'A'+'K');
	n=read();
	for (int i=1;i<=n;i++)
		A[i]=read();
	for (int i=1;i<=n;i++)
		e[i].clear();
	for (int i=1;i<n;i++){
		int a=read(),b=read();
		e[a].push_back(b);
		e[b].push_back(a);
		in[a]++,in[b]++;
	}
	if (n==2)
		return puts(A[1]==A[2]?"YES":"NO"),0;
	vector <int> rt;
	for (int i=1;rt.size()<15&&i<=n;i++)
		if (in[i]>1)
			rt=i;
	int flag=0;
	for (auto RT : rt)
		flag|=solve(RT,0)==0;
	puts(flag?"YES":"NO");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:28: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'int')
   55 |                         rt=i;
      |                            ^
In file included from /usr/include/c++/14/vector:72,
                 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/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~