
// Problem : E - Unique Color
// Contest : AtCoder - AtCoder Beginner Contest 198
// URL : https://atcoder.jp/contests/abc198/tasks/abc198_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Delete the dynamically allocated memory

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define pr              pair<long long,long long>
#define mp(a,b)         make_pair(a,b)
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fill(a,b)       memset(a, b, sizeof(a))
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)

vr ans;

void print(vr* edges,ll n,ll s,bool* vis,set<ll> &st,ll* c){
	vis[s]=true;
	if(st.find(c[s])==st.end()){
		ans.pb(s+1);
		st.insert(c[s]);
		for(ll i=0;i<edges[s].size();i++){
			if(!vis[edges[s][i]]){
				print(edges,n,edges[s][i],vis,st,c);
			}
		}
		st.erase(c[s]);
	}else{
		for(ll i=0;i<edges[s].size();i++){
			if(!vis[edges[s][i]]){
				print(edges,n,edges[s][i],vis,st,c);
			}
		}
	}
	return;
}

void DFS(vr* edges,ll n,ll* c){
	mk(vis,n,bool)
	for(ll i=0;i<n;i++){
		vis[i]=false;
	}
	set<ll> st;
	print(edges,n,0,vis,st,c);
	delete[] vis;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	mk(c,n,ll)
	for(ll i=0;i<n;i++){
		cin>>c[i];
	}
	mk(edges,n,vr)
	for(ll i=0;i<n-1;i++){
		ll u,v;
		cin>>u>>v;
		edges[u-1].pb(v-1);
		edges[v-1].pb(u-1);
	}
	DFS(edges,n,c);
	sort(ans.begin(),ans.end());
	for(ll i=0;i<ans.size();i++){
		cout<<ans[i]<<"\n";
	}
	delete[] edges;
	delete[] c;
	return 0;
}
	
	
	
	
	


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

template<class T>
struct Dijkstra {
private:
    struct Edge {
        int to;
        T cost;
    };
    
    vector<vector<Edge>> graph;
    vector<T> prev;
    
public:
    const T inf = numeric_limits<T>::max() / 2 - 1;
    vector<T> dist;
    vector<int> path;
    
    Dijkstra() {}
    Dijkstra(int n) {
        graph.resize(n);
        dist.resize(n);
        prev.resize(n);
    }
    
    void add_edge(int from, int to, T cost) {
        graph[from].push_back((Edge){to, cost});
    }
    
    void get_distance(int from) {
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
        fill(dist.begin(), dist.end(), inf);
        fill(prev.begin(), prev.end(), -1);
        dist[from] = 0;
        pq.push(make_pair(0, from));
        while(!pq.empty()) {
            pair<T, int> p = pq.top(); pq.pop();
            int cv = p.second;
            T cd = p.first;
            if (dist[cv] < cd) continue;
            for (auto e : graph[cv]) {
                T nd = dist[cv] + e.cost;
                if (dist[e.to] > nd) {
                    dist[e.to] = nd;
                    prev[e.to] = cv;
                    pq.push(make_pair(nd, e.to));
                }
            }
        }
    }
    
    void get_path(int to) {
        path = vector<int>(0);
        for (; to != -1; to = prev[to]) {
            path.push_back(to);
        }
        reverse(path.begin(), path.end());
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> c(n);
    rep(i, n) cin >> c[i];
    Dijkstra<ll> di(n);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        di.add_edge(a, b, 1);
        di.add_edge(b, a, 1);
    }
    di.get_distance(0);
    vector<bool> checked(n, false), good(n, false);
    rep(i, n) {
        if (checked[i]) {
            if (good[i]) {
                cout << (i + 1) << endl;
            }
            continue;
        }
        di.get_path(i);
        set<ll> colors;
        good[i] = true;
        for(auto &x : di.path) {
            checked[x] = true;
            good[x] = colors.count(c[x]) == 0;
            colors.insert(c[x]);
        }
        if (good[i]) cout << (i + 1) << endl;
    }
    return 0;
}
