stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

using namespace std;



int N, K;

int main(){

	cin>>N>>K;

	int num=1;

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

		if(K>num){

			num=num*2;

		}else{

			num=num+K;

		}

	}

	cout<<num;

}

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



int main (){

	int N,K,x=1;

	

	scanf ("%d",&N);

	scanf ("%d",&K);



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



		if (x*2 > x+K){

		x =	x + K;

		

		}

		else {

		x =	x * 2; 

		

		}	

	}

	printf ("%d",x);

	

	return 0;

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

using namespace std;



int main(){

	int a, k, sum = 1;

	cin >> a >> k;

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

		sum = min(sum * 2,sum + k);

	}

	cout << sum;

}




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

 

int main()

{

   int n, k, ans=1;

   

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

   

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

   	(ans+k > ans*2) ? ans*=2 : ans+=k;

   }

   

   printf("%d", ans);

   

   return 0;

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

using namespace std;



int N, K;

int main(){

	cin>>N>>K;

	int num=1;

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

		if(K>num){

			num=num*2;

		}else{

			num=num+K;

		}

	}

	cout<<num;

}

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

 

int main()

{

   int n, k, ans=1;

   

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

   

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

   	(ans+k > ans*2) ? ans*=2 : ans+=k;

   }

   

   printf("%d", ans);

   

   return 0;

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

using namespace std;



int main(){

	int a, k, sum = 1;

	cin >> a >> k;

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

		sum = min(sum * 2,sum + k);

	}

	cout << sum;

}




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



int main() {

  int N, g, output = 1;

  scanf("%d %d", &N, &g);

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

    (output+g > output*2) ? output *= 2 : output += g;

  }

  printf("%d\n", output);

  return 0;

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

using namespace std;



int N, K;

int main(){

	cin>>N>>K;

	int num=1;

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

		if(K>num){

			num=num*2;

		}else{

			num=num+K;

		}

	}

	cout<<num;

}

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



int main() {

  int N, g, output = 1;

  scanf("%d %d", &N, &g);

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

    (output+g > output*2) ? output *= 2 : output += g;

  }

  printf("%d\n", output);

  return 0;

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

using namespace std;



int main(){

	int a, k, sum = 1;

	cin >> a >> k;

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

		sum = min(sum * 2,sum + k);

	}

	cout << sum;

}




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



int main() {

  int N, K, output = 1;

  scanf("%d %d", &N, &K);

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

    (output+K > output*2) ? output *= 2 : output += K;

  }

  printf("%d\n", output);

  return 0;

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

using namespace std;



int N, K;

int main(){

	cin>>N>>K;

	int num=1;

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

		if(K>num){

			num=num*2;

		}else{

			num=num+K;

		}

	}

	cout<<num;

}

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



int main() {

  int N, K, output = 1;

  scanf("%d %d", &N, &K);

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

    (output+K > output*2) ? output *= 2 : output += K;

  }

  printf("%d\n", output);

  return 0;

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

#include<iostream>

#include<bits/stdc++.h>

#include<vector>

#include<iterator>

#include<algorithm>

#include<iomanip>

#include <string.h>

#include<set>



#define ll long long int

using namespace std;







int main(){

        ll n,k;

        cin >> n;

        cin >> k;

        ll sum=1,s=0;

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

            if(sum <= k){

                sum = sum*2;

            }

            else{

                sum += k;

            }

          //  cout << sum << " "; //for tasting error

        }

        cout << sum  << endl;

}

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

 

int main() {

    

	int N=0, K= 0, z= 1;

	scanf("%d\n%d", &N, &K);

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

		if (2 * z <= z + K) {

			z *= 2;

		} else {

			z += K;

		}

	}

 

	printf("%d\n", z);

    return 0;

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

#include<iostream>

#include<bits/stdc++.h>

#include<vector>

#include<iterator>

#include<algorithm>

#include<iomanip>

#include <string.h>

#include<set>



#define ll long long int

using namespace std;







int main(){

        ll n,k;

        cin >> n;

        cin >> k;

        ll sum=1,s=0;

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

            if(sum <= k){

                sum = sum*2;

            }

            else{

                sum += k;

            }

          //  cout << sum << " "; //for tasting error

        }

        cout << sum  << endl;

}

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



int main()

{

	int n, m;

	int ans = 1;

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

	

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

		if(ans <= m){

			ans *= 2;

		}else{

			ans += m;

		}

	}

	printf("%d\n", ans);

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

#include<iostream>

#include<bits/stdc++.h>

#include<vector>

#include<iterator>

#include<algorithm>

#include<iomanip>

#include <string.h>

#include<set>



#define ll long long int

using namespace std;







int main(){

        ll n,k;

        cin >> n;

        cin >> k;

        ll sum=1,s=0;

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

            if(sum <= k){

                sum = sum*2;

            }

            else{

                sum += k;

            }

          //  cout << sum << " "; //for tasting error

        }

        cout << sum  << endl;

}

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



int main() {

	int a, b;	

	scanf("%d %d", &a, &b);

	

	int sum = 1;

	

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

			if(sum*2 < sum+b) {

				sum = sum*2;

			}

			else if (sum*2 > sum+b) {

				sum += b;

			}

			else {

				sum = sum * 2;

			}

		}

	printf("%d", sum);



	return 0;

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

#include<iostream>

#include<bits/stdc++.h>

#include<vector>

#include<iterator>

#include<algorithm>

#include<iomanip>

#include <string.h>

#include<set>



#define ll long long int

using namespace std;







int main(){

        ll n,k;

        cin >> n;

        cin >> k;

        ll sum=1,s=0;

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

            if(sum <= k){

                sum = sum*2;

            }

            else{

                sum += k;

            }

          //  cout << sum << " "; //for tasting error

        }

        cout << sum  << endl;

}

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



int main(){

	int val, k;

	scanf("%d", &val);

	scanf("%d", &k);

	int jwb = 1;

	

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

		if(jwb < k){

			jwb *= 2;

		} else{

			jwb += k;

		}

	}

	printf("%d", jwb);

	return 0;

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

#include<iostream>

#include<bits/stdc++.h>

#include<vector>

#include<iterator>

#include<algorithm>

#include<iomanip>

#include <string.h>

#include<set>



#define ll long long int

using namespace std;







int main(){

        ll n,k;

        cin >> n;

        cin >> k;

        ll sum=1,s=0;

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

            if(sum <= k){

                sum = sum*2;

            }

            else{

                sum += k;

            }

          //  cout << sum << " "; //for tasting error

        }

        cout << sum  << endl;

}

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

int main ()

{

	int N, K;

	scanf ("%d", &N);

	scanf ("%d", &K);

	int hasil = 1;

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

	{

		if (hasil < K)

		{

			hasil *= 2;

		}

		else if (hasil >= K)

		{

			hasil += K;

		}

	}

printf ("%d", hasil);

return 0;

}
// Slower C++ solution:
/*  ***  In The Name of God ... ***  */

#include <bits/stdc++.h>



using namespace std ;



typedef long long ll ;

typedef long double ld ;





#define int long long

#define all(v) v.begin() , v.end()



template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}

template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}



const int N = 3000 + 10 ;



int n , ar [ N ] , dp [ N ] ; 

vector < int > adj [ N ] ; 

pair < int , int > pi [ N ] ; 



int32_t main()                     

{

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

	cin >> n ;

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

		cin >> ar [ i ] ;

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

		int u , v ;

		cin >> u >> v ;

		-- u , -- v ;

		adj [ u ] . push_back ( v ) ;

		adj [ v ] . push_back ( u ) ; 

	}

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

		pi [ i ] = make_pair ( ar [ i ] , i ) ;

	sort ( pi , pi + n ) ;

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

		int v = pi [ j ] . second ;

		for ( int u : adj [ v ] ) {

			if ( ar [ v ] > ar [ u ] && !dp [ u ] )

				dp [ v ] = 1 ; 

		}

	}

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

		if ( dp [ i ] )

			cout << i + 1 << ' ' ;

	cout << '\n' ; 

}


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

#include<algorithm>

using namespace std;

#define MAXN 3010

int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],c;

void AddEdge(int u,int v)

{

	c++;V[c]=v,nxt[c]=Adj[u];Adj[u]=c;

}

bool f[MAXN];

int a[MAXN],n;

void dfs(int u,int p)

{

	f[u]=0;

	for(int i=Adj[u];i;i=nxt[i])

		if(V[i]!=p)

		{

			dfs(V[i],u);

			if(f[V[i]]==0&&a[u]>a[V[i]])

				f[u]=1;

		}

}

int main()

{

	scanf("%d",&n);

	int u,v;

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

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

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

	{

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

		AddEdge(u,v);

		AddEdge(v,u);

	}

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

	{

		dfs(i,0);

		if(f[i])

			printf("%d ",i);

	}

}
// Slower C++ solution:
/*  ***  In The Name of God ... ***  */

#include <bits/stdc++.h>



using namespace std ;



typedef long long ll ;

typedef long double ld ;





#define int long long

#define all(v) v.begin() , v.end()



template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}

template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}



const int N = 3000 + 10 ;



int n , ar [ N ] , dp [ N ] ; 

vector < int > adj [ N ] ; 

pair < int , int > pi [ N ] ; 



int32_t main()                     

{

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

	cin >> n ;

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

		cin >> ar [ i ] ;

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

		int u , v ;

		cin >> u >> v ;

		-- u , -- v ;

		adj [ u ] . push_back ( v ) ;

		adj [ v ] . push_back ( u ) ; 

	}

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

		pi [ i ] = make_pair ( ar [ i ] , i ) ;

	sort ( pi , pi + n ) ;

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

		int v = pi [ j ] . second ;

		for ( int u : adj [ v ] ) {

			if ( ar [ v ] > ar [ u ] && !dp [ u ] )

				dp [ v ] = 1 ; 

		}

	}

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

		if ( dp [ i ] )

			cout << i + 1 << ' ' ;

	cout << '\n' ; 

}


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



const int N(3010);

struct edge { int next, to; } e[N << 1];

int n, A[N], head[N], e_num, ans[N];

inline void add_edge(int from, int to)

{

	e[++e_num] = (edge) {head[from], to};

	head[from] = e_num;

}



void dfs(int x, int f)

{

	ans[x] = 0;

	for (int i = head[x]; i; i = e[i].next) if (e[i].to != f && A[e[i].to] < A[x])

		{ dfs(e[i].to, x); if (!ans[e[i].to]) { ans[x] = 1; break; } }

}



int main()

{

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) scanf("%d", A + i);

	for (int i = 1, a, b; i <= n; i++)

		scanf("%d%d", &a, &b), add_edge(a, b), add_edge(b, a);

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

	return 0;

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

using namespace std;



const int N = 3e3 + 7;



vector <int> ad[N];

int a[N], n, ord[N];

bool win[N];



int main() {

	cin >> n;

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

		cin >> a[i], ord[i] = i;

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

		int x, y;

		cin >> x >> y;

		ad[x].push_back(y);

		ad[y].push_back(x);

	}

	sort (ord + 1, ord + n + 1, [](int x, int y) {

		return a[x] < a[y];

	});

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

		int v = ord[i];

		for (auto u: ad[v]) {

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

				win[v] = 1;

		}

	}

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

		if (win[i])

			cout << i << " ";





	return 0;

}

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



const int N(3010);

struct edge { int next, to; } e[N << 1];

int n, A[N], head[N], e_num, ans[N];

inline void add_edge(int from, int to)

{

	e[++e_num] = (edge) {head[from], to};

	head[from] = e_num;

}



void dfs(int x, int f)

{

	ans[x] = 0;

	for (int i = head[x]; i; i = e[i].next) if (e[i].to != f && A[e[i].to] < A[x])

		{ dfs(e[i].to, x); if (!ans[e[i].to]) { ans[x] = 1; break; } }

}



int main()

{

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) scanf("%d", A + i);

	for (int i = 1, a, b; i <= n; i++)

		scanf("%d%d", &a, &b), add_edge(a, b), add_edge(b, a);

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

	return 0;

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





using namespace std;





const int MAXN = 3000 + 3;







int n, a[MAXN];

vector<int> v, g[MAXN];









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

    bool ret = false;

    for (auto u : g[v])

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

            ret |= !dfs(u);

    return ret;

}















int main() {

    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);

    }

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

        if (dfs(i))

            cout << i + 1 << ' ';

    return 0;

}

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



const int N(3010);

struct edge { int next, to; } e[N << 1];

int n, A[N], head[N], e_num, ans[N];

inline void add_edge(int from, int to)

{

	e[++e_num] = (edge) {head[from], to};

	head[from] = e_num;

}



void dfs(int x, int f)

{

	ans[x] = 0;

	for (int i = head[x]; i; i = e[i].next) if (e[i].to != f && A[e[i].to] < A[x])

		{ dfs(e[i].to, x); if (!ans[e[i].to]) { ans[x] = 1; break; } }

}



int main()

{

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) scanf("%d", A + i);

	for (int i = 1, a, b; i <= n; i++)

		scanf("%d%d", &a, &b), add_edge(a, b), add_edge(b, a);

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

	return 0;

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

using namespace std;

const int mx =10000;

vector<int> g[mx];

int a[mx];

bool dfs(int u,int par){

    bool re=(par!=0&&a[u]>=a[par]);

    for(auto v: g[u]){

        if(v==par)continue;

        re|=!dfs(v,u);

    }

    return re;

}

int main (){

    int n,u,v;

    scanf("%d",&n);

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

        scanf("%d",a+i);

    }

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

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

        g[u].push_back(v);

        g[v].push_back(u);

    }

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

        if(dfs(i,0)){

            printf("%d ",i);

        }

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1509013890863076x):
#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>

using namespace std;

const int mx =10000;

vector<int> g[mx];

int a[mx];

bool dfs(int u,int par){

    bool re=(par!=0&&a[u]>=a[par]);

    for(auto v: g[u]){

        if(v==par)continue;

        re|=!dfs(v,u);

    }

    return re;

}

int main (){

    int n,u,v;

    scanf("%d",&n);

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

        scanf("%d",a+i);

    }

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

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

        g[u].push_back(v);

        g[v].push_back(u);

    }

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

        if(dfs(i,0)){

            printf("%d ",i);

        }

    }

    return 0;

}

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

using namespace std;



const int N = 3000 + 20;

int a[N];

vector<int> adj[N];



bool dfs(int u, int par) {

    bool res = false;

    for (auto v: adj[u])

        if (v ^ par)

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

                res = true;

    return res;

}



int main() {

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

    int n, u, v;

    cin >> n;

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

        cin >> a[i];

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

        cin >> u >> v;

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

        adj[v].push_back(u);

    }

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

        if (dfs(i, -1))

            cout << i + 1 << " ";

    cout << "\n";

    return 0;

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

#include<cstdio>

#include<cstring>

using namespace std;

 

int tot=0,h[3005];

int n,x,y,f[3005],val[3005];

struct Edge{

    int x,next;

}e[6005];

 

inline void add_edge(int x,int y){

    e[++tot].x=y;

    e[tot].next=h[x],h[x]=tot;

}

 

void dfs(int x){

    f[x]=0;

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

        if(~f[e[i].x])continue;

        dfs(e[i].x);

        if(val[e[i].x]<val[x]&&f[e[i].x]==0)f[x]=1;

    }

}

 

int main(){

    scanf("%d",&n);

    for(int i=1;i<=n;i++)scanf("%d",val+i);

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

        scanf("%d%d",&x,&y);

        add_edge(x,y);

        add_edge(y,x);

    }

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

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

        dfs(i);

        if(f[i])printf("%d ",i);

    }

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int n,tot,a[3010],head[3010],to[6010],nxt[6010];

void add_edge(int u,int v){

	nxt[++tot]=head[u];

	to[tot]=v;

	head[u]=tot;

	return;

}

bool dfs(int u,int father){

	for(int i=head[u];~i;i=nxt[i]){

		int v=to[i];

		if(v!=father)

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

				return 1;

	}

	return 0;

}

int main(){

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

	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(dfs(i,0))

			printf("%d ",i);

	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.1763692966979586x):
#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 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.7830092036484413x):
#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");

}