stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u) {

	for (int v : adj[u]) {

		if (a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		u--;

		v--;

		adj[u].pb(v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7829996315619787x):
#include<iostream>

#include<cstring>

#include<cstdio>

#include<algorithm>

#define N 3010

using namespace std;

struct edges{

	int to,pre;

}e[N<<1];int h[N],etop,a[N];

inline int add_edge(int u,int v)

{	return e[++etop].to=v,e[etop].pre=h[u],h[u]=etop;	}

int can(int x,int fa=0)

{

	for(int i=h[x];i;i=e[i].pre)

	{

		int y=e[i].to;if(y==fa) continue;

		if(a[x]>a[y]&&!can(y)) return true;

	}

	return false;

}

int main()

{

	int n;scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	for(int i=1;i<n;i++)

	{

		int u,v;scanf("%d%d",&u,&v);

		add_edge(u,v),add_edge(v,u);

	}

	for(int i=1;i<=n;i++)

		if(can(i)) printf("%d ",i);

	return !printf("\n");

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define pb push_back

#define mp make_pair

#define ld long double

#define F first

#define S second

#define pii pair<ll,ll>

 

using namespace :: std;

 

const ll maxn=3100;

const ll mod=1e9+7;

const ll inf=1e9+500;

 

ll a[maxn];

vector<ll> out[maxn];

vector<ll> in[maxn];

bool ans[maxn];

bool vis[maxn];

vector<ll> topol;

 

void dfs(ll a){

    vis[a]=1;

    for(auto v:in[a]){

        if(vis[v]==0){

            dfs(v);

        }

    }

    topol.pb(a);

}

char ansyal[maxn][maxn];

 

int main(){

    ll n;

    cin>>n;

    for(ll i=1;i<=n;i++){

        cin>>a[i];

    }

    for(ll i=1;i<n;i++){

        ll v,u;

        cin>>v>>u;

        if(a[v]!=a[u]){

            if(a[v]>a[u]){

                swap(v,u);

            }

            out[u].pb(v);

            in[v].pb(u);

        }

    }

    for(ll i=1;i<=n;i++){

        if(vis[i]==0){

            dfs(i);

        }

    }

    vector<ll> anss;

    for(ll i=n-1;i>=0;i--){

        ll v=topol[i];

        bool win=0;

        for(auto u:out[v]){

            // javab v-->u

            ansyal[v][u]='w';

            for(auto z:out[u]){

                if(ansyal[u][z]=='w'){

                    ansyal[v][u]='l';

                }

            }

            if(ansyal[v][u]=='w'){

                win=1;

            }

        }

        if(win){

            anss.pb(v);

        }

    }

    sort(anss.begin(),anss.end());

    for(auto v:anss){

        cout<<v<<' ';

    }

}

// Faster C++ solution for the same problem (measured speedup: 5.957407214854746x):
#include<cstdio>

#include<cstring>

#define maxn 3005

int n,a[maxn],ans[maxn],cnt;

bool f[maxn];

struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt;

void addedge(int u,int v)

{

	ncnt++;

	ncnt->v=v,ncnt->nxt=head[u];

	head[u]=ncnt;

}

bool dfs(int u,int fa)

{

	for(node *p=head[u];p;p=p->nxt)

	{

		int v=p->v;

		if(a[v]<a[u]&&!dfs(v,u)) return f[u]=true;

	}

	return f[u]=false;

}

int main()

{

	ncnt=&edge[0];

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	for(int i=1;i<n;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		addedge(u,v); addedge(v,u);

	}

	for(int i=1;i<=n;i++)

	{

		memset(f,0,sizeof(f));

		if(dfs(i,0)) ans[++cnt]=i;

	}

	for(int i=1;i<=cnt;i++) printf("%d ",ans[i]);

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u, int fa = -1) {

	for (int v : adj[u]) {

		if (v != fa && a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		adj[--u].pb(--v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 9.030783608189859x):
#include<cstdio>

#include<cstring>

#define maxn 3005

int n,a[maxn],ans[maxn],cnt;

bool f[maxn];

struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt;

void addedge(int u,int v)

{

	ncnt++;

	ncnt->v=v,ncnt->nxt=head[u];

	head[u]=ncnt;

}

bool dfs(int u,int fa)

{

	for(node *p=head[u];p;p=p->nxt)

	{

		int v=p->v;

		if(a[v]<a[u]&&!dfs(v,u)) return f[u]=true;

	}

	return f[u]=false;

}

int main()

{

	ncnt=&edge[0];

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	for(int i=1;i<n;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		addedge(u,v); addedge(v,u);

	}

	for(int i=1;i<=n;i++)

	{

		memset(f,0,sizeof(f));

		if(dfs(i,0)) ans[++cnt]=i;

	}

	for(int i=1;i<=cnt;i++) printf("%d ",ans[i]);

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u) {

	for (int v : adj[u]) {

		if (a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		u--;

		v--;

		adj[u].pb(v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 9.030735126420193x):
#include<cstdio>

#include<cstring>

#define maxn 3005

int n,a[maxn],ans[maxn],cnt;

bool f[maxn];

struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt;

void addedge(int u,int v)

{

	ncnt++;

	ncnt->v=v,ncnt->nxt=head[u];

	head[u]=ncnt;

}

bool dfs(int u,int fa)

{

	for(node *p=head[u];p;p=p->nxt)

	{

		int v=p->v;

		if(a[v]<a[u]&&!dfs(v,u)) return f[u]=true;

	}

	return f[u]=false;

}

int main()

{

	ncnt=&edge[0];

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	for(int i=1;i<n;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		addedge(u,v); addedge(v,u);

	}

	for(int i=1;i<=n;i++)

	{

		memset(f,0,sizeof(f));

		if(dfs(i,0)) ans[++cnt]=i;

	}

	for(int i=1;i<=cnt;i++) printf("%d ",ans[i]);

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

#include<algorithm>

#define N 3010

using namespace std;

struct edges{

	int to,pre;

}e[N<<1];int h[N],etop,a[N];

inline int add_edge(int u,int v)

{	return e[++etop].to=v,e[etop].pre=h[u],h[u]=etop;	}

int can(int x,int fa=0)

{

	for(int i=h[x];i;i=e[i].pre)

	{

		int y=e[i].to;if(y==fa) continue;

		if(a[x]>a[y]&&!can(y)) return true;

	}

	return false;

}

int main()

{

	int n;scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	for(int i=1;i<n;i++)

	{

		int u,v;scanf("%d%d",&u,&v);

		add_edge(u,v),add_edge(v,u);

	}

	for(int i=1;i<=n;i++)

		if(can(i)) printf("%d ",i);

	return !printf("\n");

}

// Faster C++ solution for the same problem (measured speedup: 5.0642321519076114x):
#include<cstdio>

#include<cstring>

#define maxn 3005

int n,a[maxn],ans[maxn],cnt;

bool f[maxn];

struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt;

void addedge(int u,int v)

{

	ncnt++;

	ncnt->v=v,ncnt->nxt=head[u];

	head[u]=ncnt;

}

bool dfs(int u,int fa)

{

	for(node *p=head[u];p;p=p->nxt)

	{

		int v=p->v;

		if(a[v]<a[u]&&!dfs(v,u)) return f[u]=true;

	}

	return f[u]=false;

}

int main()

{

	ncnt=&edge[0];

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	for(int i=1;i<n;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		addedge(u,v); addedge(v,u);

	}

	for(int i=1;i<=n;i++)

	{

		memset(f,0,sizeof(f));

		if(dfs(i,0)) ans[++cnt]=i;

	}

	for(int i=1;i<=cnt;i++) printf("%d ",ans[i]);

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u, int fa = -1) {

	for (int v : adj[u]) {

		if (v != fa && a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		adj[--u].pb(--v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6270965607320622x):
#include <bits/stdc++.h>





using namespace std;





const int MAXN = 3000 + 23;



















int n, a[MAXN];

vector<int> g[MAXN];

bitset<MAXN> mark;



void inp();

void dfs(int, int = -1);



int main() {

    inp();

    for (int i = 0; i < n; i++) {

        mark.reset();

        dfs(i);

        if (mark[i])

            cout << i + 1 << ' ';

    }

    return 0;

}

void inp() {

    cin >> n;

    for (int i = 0; i < n; i++) cin >> a[i];

    for (int i = 1; i < n; i++) {

        int u, v;

        cin >> u >> v;

        g[--u].push_back(--v), g[v].push_back(u);

    }

}

void dfs(int v, int p) {

    for (auto u : g[v]) if (u != p) dfs(u, v);

    for (auto u : g[v]) if (!mark[u] && a[v] > a[u]) mark[v] = true;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u) {

	for (int v : adj[u]) {

		if (a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		u--;

		v--;

		adj[u].pb(v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6270884326002912x):
#include <bits/stdc++.h>





using namespace std;





const int MAXN = 3000 + 23;



















int n, a[MAXN];

vector<int> g[MAXN];

bitset<MAXN> mark;



void inp();

void dfs(int, int = -1);



int main() {

    inp();

    for (int i = 0; i < n; i++) {

        mark.reset();

        dfs(i);

        if (mark[i])

            cout << i + 1 << ' ';

    }

    return 0;

}

void inp() {

    cin >> n;

    for (int i = 0; i < n; i++) cin >> a[i];

    for (int i = 1; i < n; i++) {

        int u, v;

        cin >> u >> v;

        g[--u].push_back(--v), g[v].push_back(u);

    }

}

void dfs(int v, int p) {

    for (auto u : g[v]) if (u != p) dfs(u, v);

    for (auto u : g[v]) if (!mark[u] && a[v] > a[u]) mark[v] = true;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u, int fa = -1) {

	for (int v : adj[u]) {

		if (v != fa && a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		adj[--u].pb(--v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6279453510807205x):
#include <bits/stdc++.h>

using namespace std;



const int MAXN = 3000 + 10;

int a[MAXN];

vector <int> adj[MAXN];



bool dfs(int v, int p = -1) {

	for (int i: adj[v])

		if (i != p) {

			if (a[i] >= a[v])

				continue;

			else if(!dfs(i, v))

				return true;

		}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)

		cin >> a[i];

	for (int i = 0; i < n - 1; i++) {

		int a, b;

		cin >> a >> b;

		a--, b--;

		adj[a].push_back(b);

		adj[b].push_back(a);

	}

	for (int i = 0; i < n; i++)

		if (dfs(i))

			cout << i + 1 << ' ';

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u) {

	for (int v : adj[u]) {

		if (a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		u--;

		v--;

		adj[u].pb(v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6279366114546856x):
#include <bits/stdc++.h>

using namespace std;



const int MAXN = 3000 + 10;

int a[MAXN];

vector <int> adj[MAXN];



bool dfs(int v, int p = -1) {

	for (int i: adj[v])

		if (i != p) {

			if (a[i] >= a[v])

				continue;

			else if(!dfs(i, v))

				return true;

		}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)

		cin >> a[i];

	for (int i = 0; i < n - 1; i++) {

		int a, b;

		cin >> a >> b;

		a--, b--;

		adj[a].push_back(b);

		adj[b].push_back(a);

	}

	for (int i = 0; i < n; i++)

		if (dfs(i))

			cout << i + 1 << ' ';

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u, int fa = -1) {

	for (int v : adj[u]) {

		if (v != fa && a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		adj[--u].pb(--v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6080380534531404x):
#include <bits/stdc++.h>

using namespace std;



#define pb push_back

#define ff first

#define ss second



const long long MAXN = 3e3 + 21, LG = 20, inf = 1e18;



int n;

int a[MAXN];

bool dp[MAXN];

vector<int> adj[MAXN];



void dfs(int v, int par = -1){

    dp[v] = 0;

    for(auto &y: adj[v])

        if(y ^ par && a[v] > a[y]) {

            dfs(y, v);

            dp[v] |= (!dp[y]);

        }

}



int main(){

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    for(int i = 1; i <= n; i++)

        cin >> a[i];

    for(int i = 1; i < n; i++) {

        int u, v;

        cin >> u >> v;

        adj[u].pb(v);

        adj[v].pb(u);

    }



    for(int i = 1; i <= n; i++){

        dfs(i);

        if(dp[i]) 

            cout << i << ' ';

    }

    cout <<'\n';

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u) {

	for (int v : adj[u]) {

		if (a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		u--;

		v--;

		adj[u].pb(v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.60802942069945x):
#include <bits/stdc++.h>

using namespace std;



#define pb push_back

#define ff first

#define ss second



const long long MAXN = 3e3 + 21, LG = 20, inf = 1e18;



int n;

int a[MAXN];

bool dp[MAXN];

vector<int> adj[MAXN];



void dfs(int v, int par = -1){

    dp[v] = 0;

    for(auto &y: adj[v])

        if(y ^ par && a[v] > a[y]) {

            dfs(y, v);

            dp[v] |= (!dp[y]);

        }

}



int main(){

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    for(int i = 1; i <= n; i++)

        cin >> a[i];

    for(int i = 1; i < n; i++) {

        int u, v;

        cin >> u >> v;

        adj[u].pb(v);

        adj[v].pb(u);

    }



    for(int i = 1; i <= n; i++){

        dfs(i);

        if(dp[i]) 

            cout << i << ' ';

    }

    cout <<'\n';

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u, int fa = -1) {

	for (int v : adj[u]) {

		if (v != fa && a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		adj[--u].pb(--v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6510230228997336x):
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<iostream>

using namespace std;

#define ll long long

#define REP(a,b,c) for(int a=b;a<=c;a++)

#define re register

#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)

typedef pair<int,int> pii;

#define mp make_pair

inline int gi()

{

	int f=1,sum=0;char ch=getchar();

	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}

	return f*sum;

}

const int N=3010;

int n,A[N],sg[N];

vector<int>G[N];

void dfs(int u,int ff)

{

	for(int v:G[u])

		if(v!=ff&&A[v]<A[u])dfs(v,u),sg[u]|=sg[v]^1;

}

int main()

{

	n=gi();

	for(int i=1;i<=n;i++)A[i]=gi();

	for(int i=1;i<n;i++)

	{

		int u=gi(),v=gi();

		G[u].push_back(v);G[v].push_back(u);

	}

	for(int i=1;i<=n;i++){dfs(i,i);if(sg[i])printf("%d ",i);}

	puts("");

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u) {

	for (int v : adj[u]) {

		if (a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		u--;

		v--;

		adj[u].pb(v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6510141593811973x):
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<iostream>

using namespace std;

#define ll long long

#define REP(a,b,c) for(int a=b;a<=c;a++)

#define re register

#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)

typedef pair<int,int> pii;

#define mp make_pair

inline int gi()

{

	int f=1,sum=0;char ch=getchar();

	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}

	return f*sum;

}

const int N=3010;

int n,A[N],sg[N];

vector<int>G[N];

void dfs(int u,int ff)

{

	for(int v:G[u])

		if(v!=ff&&A[v]<A[u])dfs(v,u),sg[u]|=sg[v]^1;

}

int main()

{

	n=gi();

	for(int i=1;i<=n;i++)A[i]=gi();

	for(int i=1;i<n;i++)

	{

		int u=gi(),v=gi();

		G[u].push_back(v);G[v].push_back(u);

	}

	for(int i=1;i<=n;i++){dfs(i,i);if(sg[i])printf("%d ",i);}

	puts("");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define pb push_back

#define mp make_pair

#define ld long double

#define F first

#define S second

#define pii pair<ll,ll>

 

using namespace :: std;

 

const ll maxn=3100;

const ll mod=1e9+7;

const ll inf=1e9+500;

 

ll a[maxn];

vector<ll> out[maxn];

vector<ll> in[maxn];

bool ans[maxn];

bool vis[maxn];

vector<ll> topol;

 

void dfs(ll a){

    vis[a]=1;

    for(auto v:in[a]){

        if(vis[v]==0){

            dfs(v);

        }

    }

    topol.pb(a);

}

char ansyal[maxn][maxn];

 

int main(){

    ll n;

    cin>>n;

    for(ll i=1;i<=n;i++){

        cin>>a[i];

    }

    for(ll i=1;i<n;i++){

        ll v,u;

        cin>>v>>u;

        if(a[v]!=a[u]){

            if(a[v]>a[u]){

                swap(v,u);

            }

            out[u].pb(v);

            in[v].pb(u);

        }

    }

    for(ll i=1;i<=n;i++){

        if(vis[i]==0){

            dfs(i);

        }

    }

    vector<ll> anss;

    for(ll i=n-1;i>=0;i--){

        ll v=topol[i];

        bool win=0;

        for(auto u:out[v]){

            // javab v-->u

            ansyal[v][u]='w';

            for(auto z:out[u]){

                if(ansyal[u][z]=='w'){

                    ansyal[v][u]='l';

                }

            }

            if(ansyal[v][u]=='w'){

                win=1;

            }

        }

        if(win){

            anss.pb(v);

        }

    }

    sort(anss.begin(),anss.end());

    for(auto v:anss){

        cout<<v<<' ';

    }

}

// Faster C++ solution for the same problem (measured speedup: 1.1622932288548946x):
#include<bits/stdc++.h>

using namespace std;

const int N=3010;

int head[N],cnt,n;

struct edge

{

	int to,next;

}e[N<<1];

void adde(int a,int b)

{

	e[++cnt].to=b; e[cnt].next=head[a]; head[a]=cnt;

}

int a[N],ans[N];

void dfs(int k)

{

	ans[k]=0;

	for(int i=head[k];i;i=e[i].next)

	{

		int v=e[i].to;

		if(a[k]>a[v])

		{

			if(ans[v]==-1)

				dfs(v);

			if(ans[v]==0){ans[k]=1;return;}

		}

	}

}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	memset(ans,-1,sizeof(ans));

	int u,v;

	for(int i=1;i<n;i++)

		scanf("%d%d",&u,&v),adde(u,v),adde(v,u);

	for(int i=1;i<=n;i++)

	{

		if(ans[i]==-1)dfs(i);

		if(ans[i]==1)

			printf("%d ",i);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define pb push_back



using namespace std;



const int MAXN = 3e4 + 10;



int a[MAXN];



vector<int> adj[MAXN];



bool dfs(int u, int fa = -1) {

	for (int v : adj[u]) {

		if (v != fa && a[v] < a[u] && !dfs(v))

			return true;

	}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

		cin >> a[i];

	for (int i = 1; i < n; ++i) {

		int u, v;

		cin >> u >> v;

		adj[--u].pb(--v);

		adj[v].pb(u);

	}

	for (int i = 0; i < n; i++) {

		if (dfs(i))

			cout << i + 1 << " ";

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7616711258124287x):
#include<bits/stdc++.h>

using namespace std;

const int N=3010;

int head[N],cnt,n;

struct edge

{

	int to,next;

}e[N<<1];

void adde(int a,int b)

{

	e[++cnt].to=b; e[cnt].next=head[a]; head[a]=cnt;

}

int a[N],ans[N];

void dfs(int k)

{

	ans[k]=0;

	for(int i=head[k];i;i=e[i].next)

	{

		int v=e[i].to;

		if(a[k]>a[v])

		{

			if(ans[v]==-1)

				dfs(v);

			if(ans[v]==0){ans[k]=1;return;}

		}

	}

}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	memset(ans,-1,sizeof(ans));

	int u,v;

	for(int i=1;i<n;i++)

		scanf("%d%d",&u,&v),adde(u,v),adde(v,u);

	for(int i=1;i<=n;i++)

	{

		if(ans[i]==-1)dfs(i);

		if(ans[i]==1)

			printf("%d ",i);

	}

	return 0;

}