#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int N;
int A[3000];
bool used[3000];
vector<int> G[3000];
vector<int> ans;

bool allSameWeight(vector<int> v){
    int min_a = 2e+9;
    int max_a = -100;
    for(int i = 0; i < v.size(); i++){
        min_a = min(min_a, A[v[i]]);
        max_a = max(max_a, A[v[i]]);
    }
    if(min_a == max_a) return true;
    else return false;
}

void solve(vector<int> v){
    // for(int i = 0; i < v.size(); i++) cout << v[i] << ' ';
    // cout << endl;
    if(v.size() == 1) {
        used[v[0]] = true;
        return;
    }
    if(allSameWeight(v)) return;
    int min_v = -1;
    for(int i = 0; i < v.size(); i++){
        int max_a = -1;
        for(int j = 0; j < G[v[i]].size(); j++){
            if(!used[G[v[i]][j]] && A[v[i]] > A[G[v[i]][j]]) break;
            if(!used[G[v[i]][j]]) max_a = max(max_a, A[G[v[i]][j]]);
            if(j+1 == G[v[i]].size() && max_a > A[v[i]]) min_v = v[i];
        }
        if(min_v != -1) break;
    }
    // check all weight is same around
    for(int i = 0; i < v.size(); i++){
        int max_a = -1;
        int min_a = 2e+9;
        for(int j = 0; j < G[v[i]].size(); j++){
            if(!used[G[v[i]][j]]){
                min_a = min(min_a, A[G[v[i]][j]]);
                max_a = max(max_a, A[G[v[i]][j]]);
            }
        }
        if(min_a == A[v[i]] && max_a == A[v[i]]){
            used[v[i]] = true;
        }
    }
    // cout << min_v << endl;
    used[min_v] = true;
    for(int i = 0; i < G[min_v].size(); i++){
        if(!used[G[min_v][i]] && A[G[min_v][i]] > A[min_v]){
            used[G[min_v][i]] = true;
            ans.push_back(G[min_v][i]);
        }
    }
    UnionFind uf(v.size());
    int idx[3000];
    for(int i = 0; i < v.size(); i++) idx[v[i]] = i;
    for(int i = 0; i < v.size(); i++){
        if(!used[v[i]]){
            for(int j = 0; j < G[v[i]].size(); j++){
                if(!used[G[v[i]][j]]) {
                    uf.unionSet(idx[v[i]], idx[G[v[i]][j]]);
                }
            }
        }
    }
    map<int, vector<int>> mp;
    for(int i = 0; i < v.size(); i++){
        if(!used[v[i]]){
            int r = uf.root(i);
            mp[r].push_back(v[i]);
        }
    }
    for(auto iter = mp.begin(); iter != mp.end(); iter++){
        solve(iter->second);
    }
}

int main(){
    cin >> N;
    vector<int> v;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) v.push_back(i);
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    solve(v);
    if(ans.size() != 0) sort(ans.begin(), ans.end());
    for(int i = 0; i  < ans.size(); i++){
        cout << ans[i]+1;
        if(i+1 < ans.size()) cout << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 8192