#include "bits/stdc++.h"
using namespace std;
#define pb push_back
const int maxx = 100005;
int n , c[maxx];
vector<int> edge[maxx];
int asd[maxx];
multiset<int> s;
vector<int> ans;
void dfs(int u)
{
    s.insert(c[u]);
    asd[u] = 1;
    for(int i : edge[u])
    {
        if(!asd[i])
        {
            if(!s.count(c[i])) ans.pb(i);
            dfs(i);
            set<int>:: iterator it = s.lower_bound(c[i]);
            if(it != s.end()) s.erase(it);
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    cin >> n ;
    for(int i = 1; i <= n; ++i)
    {
        cin >> c[i];
    }
    for(int i = 1 ; i < n ; ++i) {
        int u , v; cin >> u >> v;
        edge[u].pb(v);
        edge[v].pb(u);
    }
    dfs(1);
    ans.pb(1);
    sort(begin(ans),end(ans));
    for(int i : ans ) cout << i << '\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

const int MAX_N = 1e5 + 10;
int n;
vi c(MAX_N);
vc<bool> used(MAX_N, false);
vi ans;
vvi to(MAX_N);
void dfs (int now, int p) {
    for (int nxt : to[now]) {
        if (nxt == p) continue;
        if (!used[c[nxt]]) {
            ans.eb(nxt);
            used[c[nxt]] = true;
            dfs(nxt, now);
            used[c[nxt]] = false;
            continue;
        }
        dfs(nxt, now);
    }
}

int main () {
    cin >> n;
    rep(i, n) cin >> c[i];
    rep(i, n-1) {
        int a, b; cin >> a >> b, a--, b--;
        to[a].eb(b);
        to[b].eb(a);
    }
    ans.eb(0);
    used[c[0]] = true;
    dfs(0, -1);
    sort(all(ans));
    rep(i, sz(ans)) cout << ans[i] + 1 << endl;
    return 0;
}