Language: C++

#include<bits/stdc++.h>
using namespace std;
int n,i,j,A[2000000],x,y;
int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
bool lost[2000000],win[2000000];
inline void add(int x,int y)
{
	top++,to[top]=y;
	if(first[x]==0)first[x]=top;else next[last[x]]=top;
	last[x]=top;
}
void dfs(int x)
{
	int mn=2100000000,i=first[x];
	while (i)
	{
		mn=min(A[to[i]],mn);
		i=next[i];
	}
	if(mn>=A[x])lost[x]=true;
	if(lost[x])
	{
		i=first[x];
		while (i)
		{
			if(A[to[i]]>A[x])win[to[i]]=true;
			i=next[i];
		}
	}
	i=first[x];
	while (i)
	{
		if(fa[to[i]]!=x)fa[to[i]]=x,dfs(to[i]);
		i=next[i];
	}
}
inline int read()
{
    char ch=getchar();int ret=0,flag=1;
    while(ch<'0'||ch>'9') {if(ch=='-') flag=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
    return ret*flag;
}
int main()
{
	n=read();
	for (i=1;i<=n;i++)A[i]=read();
	for (i=1;i<n;i++)x=read(),y=read(),add(x,y),add(y,x);
	fa[1]=1;
	dfs(1);
	for (i=1;i<=n;i++)if(win[i])printf("%d ",i);
	return 0;
}

Compiler output:
a.cc: In function 'void add(int, int)':
a.cc:9:42: error: reference to 'next' is ambiguous
    9 |         if(first[x]==0)first[x]=top;else next[last[x]]=top;
      |                                          ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:4:36: note:                 'int next [5000000]'
    4 | int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
      |                                    ^~~~
a.cc: In function 'void dfs(int)':
a.cc:18:19: error: reference to 'next' is ambiguous
   18 |                 i=next[i];
      |                   ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:4:36: note:                 'int next [5000000]'
    4 | int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
      |                                    ^~~~
a.cc:27:27: error: reference to 'next' is ambiguous
   27 |                         i=next[i];
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:4:36: note:                 'int next [5000000]'
    4 | int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
      |                                    ^~~~
a.cc:34:19: error: reference to 'next' is ambiguous
   34 |                 i=next[i];
      |                   ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:4:36: note:                 'int next [5000000]'
    4 | int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
      |                                    ^~~~