#include <bits/stdc++.h>

#include <unordered_set>
#include <vector>
// #include <atcoder/all>
// using namespace atcoder;

using namespace std;
using ll = long long;

// using Graph = vector<vector<int>>;
vector<bool> visited;
vector<bool> good;
vector<int> C;
vector<int> G[100009];

void dfs(int v, vector<int> &color) {
    if (0 == color[C[v]]) good[v] = true;
    color[C[v]]++;
    visited[v] = true;
    for (int next_v : G[v]) {
        if (visited[next_v]) continue;
        dfs(next_v, color);
    }
    color[C[v]]--;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> color(100009, 0);

    // Graph G(N);
    C.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> C[i], C[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);
    }

    visited.assign(N, false);
    good.assign(N, false);
    dfs(0, color);

    for (int i = 0; i < N; i++) {
        if (good[i]) {
            cout << i + 1 << endl;
        }
    }

    return 0;
}

/* code of Ayush Tiwari
    codeforces- servermonk
    codechef- ayush572000
*/

#include <bits/stdc++.h>
#define ll long long

//STL
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair 
#define all(v) v.begin(), v.end()

//loops
#define forn(i,a,b) for(int i=a;  i<b; i++)
#define rforn(i,a,b) for(int i=a; i>=b; i--)

// defined values
#define maxn 200004
#define Mod 1000000007

// fast io
#define FIO() ios_base::sync_with_stdio(0);cin.tie(0);


using namespace std;

vector<int> graph[maxn];
map<int,int> m;
int a[maxn];
int vis[maxn];

void dfs(int node,int flag){
    vis[node]=flag;
    m[a[node-1]]+=1;
    for(auto child: graph[node]){
        if(vis[child]) continue;
        if(!m[a[child-1]])
            dfs(child,1);
        else dfs(child,2);
    }    
    m[a[node-1]]-=1;
}

void solution(){

    // This is the main code
    int n;
    cin>>n;
    forn(i,0,n) cin>>a[i];
    forn(i,0,n-1){
        int u,v;
        cin>>u>>v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    dfs(1,1);
    forn(i,1,n+1){
        if(vis[i]==1) cout<<i<<endl;;
    }
}


int main(){
    
    #ifndef ONLINE_JUDGE
    freopen("D:/competitive-programming/input.txt","r",stdin);
    freopen("D:/competitive-programming/output.txt","w",stdout);
    #endif  
    
    FIO()   
    
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solution();
    }
    return 0;
}