
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <tuple>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <map>
#include <numeric>
#include <cassert>

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for(ll i=0;i<(ll)n;i++)
#define REPab(i,a,b)for(ll i=(ll)a;i<(ll)b;i++)
constexpr bool bitp(ull bits, ull pos) { return bits & (1ULL << pos); }
constexpr ll mod(ll val, ll m) { return (val >= 0) ? (val % m) : (val % m + m); }
template <class T> void chmin(T& a, T b) { a = std::min(a, b); }
template <class T> void chmax(T& a, T b) { a = std::max(a, b); }

int main() {
    ll N; std::cin >> N;
    std::vector<ll> C(N);
    std::vector<std::vector<ll>> routes(N);
    REP(i, N) std::cin >> C[i];
    REP(i, N-1) {
        ll a, b;
        std::cin >> a >> b;
        routes[a - 1].push_back(b - 1);
        routes[b - 1].push_back(a - 1);
    }
    std::vector<ll> goods;
    std::unordered_set<ll> map;
    const auto search = [&](auto&& search, ll node, ll parent) -> void {
        const auto it = map.find(C[node]);
        if (it == map.end()) {
            goods.push_back(node);
            map.insert(C[node]);
            for (const auto& child : routes[node]) {
                if (child != parent) {
                    search(search, child, node);
                }
            }
            map.erase(C[node]);
        }
        else {
            for (const auto& child : routes[node]) {
                if (child != parent) {
                    search(search, child, node);
                }
            }
        }
    };
    search(search, 0, -1);
    std::sort(goods.begin(), goods.end());
    for (const auto& g : goods) {
        std::cout << g + 1 << "\n";
    }
}

#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long 
#define pb push_back
#define all(v) v.begin(),v.end()
const int INF=1e9+7;
const int N=1e5+5;
int col[N],frec[N];
vector<int>adj[N];
vector<int>ans;
void dfs(int node,int pa){
	frec[col[node]]++;
	
	if(frec[col[node]]==1)
		ans.pb(node);
		
	for(auto p:adj[node]){
		if(p==pa)continue;
		dfs(p,node);
	}	
	frec[col[node]]--;
}
	
int main(){
	FAST;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>col[i];
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}	
	dfs(0,-1);	
	sort(all(ans));
	for(auto p:ans)
		cout<<p+1<<endl;
		
	return 0;
}
