Language: C++

#pragma GCC optimize(3)
#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:10:42: error: reference to 'next' is ambiguous
   10 |         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:2:
/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:5:36: note:                 'int next [5000000]'
    5 | int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
      |                                    ^~~~
a.cc: In function 'void dfs(int)':
a.cc:19:19: error: reference to 'next' is ambiguous
   19 |                 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:5:36: note:                 'int next [5000000]'
    5 | int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
      |                                    ^~~~
a.cc:28:27: error: reference to 'next' is ambiguous
   28 |                         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:5:36: note:                 'int next [5000000]'
    5 | int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
      |                                    ^~~~
a.cc:35:19: error: reference to 'next' is ambiguous
   35 |                 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:5:36: note:                 'int next [5000000]'
    5 | int fa[2000000],first[2000000],top,next[5000000],last[5000000],to[5000000];
      |                                    ^~~~