#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()
using ll = long long;
using P = pair<ll,ll>;

int n;
vector<int> c(100005);
vector<bool> ok(100005,false);
vector<bool> visited(100005,false);

vector<int> g[100005];
vector<int> cnt(100005,0);

void dfs(int x){
    visited[x] = true;
    if(cnt[c[x]]==0){
        ok[x] = true;
    }

    cnt[c[x]]++;
    for(auto next:g[x]){
        if(visited[next]) continue;
        dfs(next);
    }
    cnt[c[x]]--;
}

int main(){
    cin >> n;
    rep(i,n){
        cin >> c[i];
    }

    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dfs(0);

    rep(i,n){
        if(ok[i]){
            cout << i+1 << endl;
        }
    }
}
#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

const int mxn=2e5+5;

int c[mxn];
vector<int> g[mxn];
map<int, int> mp;
set<int> ans;

void dfs(int x, int p){
    if(mp[c[x]]==0)
        ans.insert(x);
    mp[c[x]]++;
    for(auto y:g[x]){
        if(y==p)
         continue;
        dfs(y, x);
    }
    mp[c[x]]--;
}

int main()
{
	int n,i;
    cin>>n;
    
    for(i=1; i<=n; i++) 
    	cin>>c[i];
    
    for(i=0; i<n-1; i++){
        int a, b; 
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, -1);

    for(auto x:ans) 
    	cout<<x<<'\n';
}