Problem:
Score : 1600 points

Problem Statement

There is a tree with N vertices, numbered 1 through N.
The i-th of the N-1 edges connects vertices a_i and b_i.

Currently, there are A_i stones placed on vertex i.
Takahashi and Aoki will play a game using this tree.

First, Takahashi will select a vertex and place a piece on it.
Then, starting from Takahashi, they will alternately perform the following operation:

Remove one stone from the vertex currently occupied by the piece.

Then, move the piece to a vertex that is adjacent to the currently occupied vertex.

The player who is left with no stone on the vertex occupied by the piece and thus cannot perform the operation, loses the game.
Find all the vertices v such that Takahashi can place the piece on v at the beginning and win the game.

Constraints

2 ≦ N ≦ 3000

1 ≦ a_i,b_i ≦ N

0 ≦ A_i ≦ 10^9

The given graph is a tree.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 … A_N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

Print the indices of the vertices v such that Takahashi can place the piece on v at the beginning and win the game, in a line, in ascending order.

Sample Input 1

3
1 2 3
1 2
2 3

Sample Output 1

2

The following is one possible progress of the game when Takahashi places the piece on vertex 2:

Takahashi moves the piece to vertex 1. The number of the stones on each vertex is now: (1,1,3).

Aoki moves the piece to vertex 2. The number of the stones on each vertex is now: (0,1,3).

Takahashi moves the piece to vertex 1. The number of the stones on each vertex is now: (0,0,3).

Aoki cannot take a stone from the vertex, and thus Takahashi wins.

Sample Input 2

5
5 4 1 2 3
1 2
1 3
2 4
2 5

Sample Output 2

1 2

Sample Input 3

3
1 1 1
1 2
2 3

Sample Output 3

Note that the correct output may be an empty line.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a[3010],x,y;
vector<int> g[3010];

int solve();
int color(int n,int li[]);

int main(){
	cin >> n;
	REP(i,0,n) cin >> a[i];
	REP(i,0,n-1) cin >> x >> y,g[x-1].push_back(y-1),g[y-1].push_back(x-1);
	
	solve();
	return 0;
}

int solve(){
	vector<int> vec;
	REP(N,0,n){
		int co[3010];
		color(N,co);
		queue<P> qu;
		for(auto e:g[N]) if(a[N]>a[e]) qu.push(P(e,N));
		
		while(!qu.empty()){
			auto p=qu.front(); qu.pop();
			
			bool f=true;
			for(auto e:g[p.first]){
				if(a[p.first]<a[e]) continue;
				if(p.second==e) continue;
				f=false;
				qu.push(P(e,p.first));
			}
			
			if(f and co[p.first]==2){vec.push_back(N); break;}
		}
	}

	for(auto s:vec) cout << s+1 << " ";
	cout << endl;
	return 0;
}

int color(int s, int li[]){
	queue<P> qu;
	qu.push(P(s,1));
	REP(i,0,n) li[i]=0;
	li[s]=1;
	
	while(!qu.empty()){
		auto p=qu.front(); qu.pop();
		
		for(auto e:g[p.first]){
			if(li[e]) continue;
			li[e]=(p.second-1?1:2);
			
			qu.push(P(e,li[e]));
		}
	}
	
	return 0;
}