#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, c);
    vc<vc<int>> e(n);
    Rep(n-1){
        Cin(int, a, b); a--, b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    
    unordered_set<int> cs;
    set<int> ans;
    auto f = [&](int i, int par, auto self) -> void {
        bool good = cs.count(c[i]) == 0;
        if(good){
            ans.insert(i+1);
            cs.insert(c[i]);
        }
        for(const int &j : e[i]) if(j != par) self(j, i, self);
        if(good) cs.erase(c[i]);
    };
    f(0, -1, f);
    Couts(ans);
}






#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
template<class T>
class MS{
    public:
        set<T> st;
        map<T, int> cnt;
        int size = 0;
        MS(){}
        void insert(T x){
            st.insert(x);
            size++;
            cnt[x] += 1;
        }
        void remove(T x){
            if(cnt[x] == 0) return;
            cnt[x] -= 1;
            size--;
            if(cnt[x] == 0) st.erase(x);
        }
        bool find(T x){
            return (cnt[x] > 0);
        }
        T begin(){
            return *st.begin();
        }
        T rbegin(){
            return *st.rbegin();
        } 
};
vector<vector<int>> adj;
int N;
vector<int> C;
MS<int> path;
vector<int> ans;

void DFS(int u, int p = -1){
    // cout << u << endl;
    if(!path.find(C[u])) ans.push_back(u);
    path.insert(C[u]);
    for(int v: adj[u]){
        if(v == p) continue;
        DFS(v, u);
        path.remove(C[v]);
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    C.resize(N + 1);
    adj.resize(N + 1);
    for(int i = 1; i <= N; i++){
        cin >> C[i];
    }
    for(int i = 0, a, b; i < N - 1; i++){
        cin >> a >> b;
        // cout << a << " " << b << endl;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    DFS(1);
    sort(ans.begin(), ans.end());
    for(int i: ans) cout << i << "\n";
    return 0;
}
