#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=3005;
int h[N],ne[N<<1],to[N<<1],sg[N],a[N];
int n,tot;
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
void dfs(int x,int las) {
	sg[x]=0;
	for(RI i=h[x];i;i=ne[i]) {
		if(to[i]==las) continue;
		dfs(to[i],x);
		if(a[to[i]]<a[x]&&!sg[to[i]]) sg[x]=1;
	}
}
int main()
{
	int x,y;
	n=read();
	for(RI i=1;i<=n;++i) a[i]=read();
	for(RI i=1;i<n;++i) x=read(),y=read(),add(x,y),add(y,x);
	for(RI i=1;i<=n;++i) {dfs(i,0);if(sg[i]) printf("%d ",i);}
	return 0;
}