#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const ll INF = 1LL << 60;
const double pi = acos(-1);
ll mod = 1000000007;

struct Edge {
    int to;
    long long w;
    Edge(int to, long long w) : to(to), w(w) {}
};

struct dsu {
    vector<int> d;
    dsu(int n = 0): d(n,-1) {}
    int findRoot(int x) {
        if(d[x] < 0) return x;
        return d[x] = findRoot(d[x]);
    }
    bool unite(int x,int y) {
        x = findRoot(x); y = findRoot(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) { return findRoot(x) == findRoot(y);}
    int size(int x) {return -d[findRoot(x)];}
};

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

template <typename T>
T my_lower_bound(vector<T> a, T lb, T ub, T k) {
    while(ub - lb > 1) {
        T mid = (lb + ub) / 2;
        if(a[mid] >= k) {
            ub = mid;
        }else{
            lb = mid;
        }
    }
    return ub;
}

set<int> group;
vector<vector<int>> g;
vector<int> c, ans;
vector<bool> ch;

void dfs(int i) {
    for(auto t : g[i]) {
        if(ch[t]) continue;
        auto x = group.find(c[t]);
        if(x == group.end()) {
            group.insert(c[t]);
            ans.push_back(t);
            ch[t] = true;
            dfs(t);
            group.erase(c[t]);
            ch[t] = false;
        }else{
            ch[t] = true;
            dfs(t);
            ch[t] = false;
        }
    }
}

int main() {
    int n; cin >> n;
    c.resize(n + 1);
    ch.resize(n + 1, false);
    rep1(i,n) cin >> c[i];
    g.assign(n + 1, vector<int>());
    rep1(i,n - 1) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    group.insert(c[1]);
    ans.push_back(1);
    ch[1] = true;
    dfs(1);
    sort(ans.begin(),ans.end());
    for(auto t : ans) {
        cout << t << endl;
    }
    return 0;
}

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector<int> good;
map<int,vector<int>> adj;
map<int,int> color;
map<int,int> mark;
void dfs(int node,vector<bool> &visited){
    visited[node]=1;
    if(mark.count(color[node])==0){
        mark[color[node]]=1;
    }else mark[color[node]]++;
    for(int i:adj[node]){
        if(!visited[i]){
            dfs(i,visited);
        }
    }
    if(mark[color[node]]==1){
        good.push_back(node);
    }
    mark[color[node]]--;
}

int main(){
    int vertex;
    cin>>vertex;
    int x,y;
    for(int i=0;i<vertex;i++){
        cin>>x;
        color[i+1]=x;
    }
    for(int i=0;i<vertex-1;i++){
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    vector<bool> visited(vertex+1);
    dfs(1,visited);
    sort(good.begin(),good.end());
    for(int i:good){
        cout<<i<<"\n";
    }
    return 0;
}