
/*
			Sunday 11 April 2021 06:07:10 PM IST
					@uthor::astrainL3gi0N
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::pair<int,int> ii;
#define debg(x)	std::cerr<<(#x)<<" => "<<x<<'\n';
#define debgg(x,y)	std::cerr<<(#x)<<" => "<<x<<'\t'<<(#y)<<' '<<y<<'\n';
#define len(a) (int)(a).size()
#define all(x) x.begin(),x.end()
const int mod = 1000000007;
//const int mod = 998244353;

bool comp (int x, int y) {
    return x > y;
}
void printarr (int arr[], int n) {
    for(int i = 0; i < n; ++i)
        std::cerr<<arr[i]<<(i<n-1?' ':'\n');
}
template < typename T> void  printv (T &a) {
    for (auto it = a.begin(); it != a.end(); ++it)
        std::cerr<<*it<<' ';
    std::cerr<<'\n';
}
    

const int maxn = 100009;
//int t[510][510];
ll ans;
int arr[maxn];
int visited[maxn];
vi adj[maxn];
map <int,int> mp;
vi res;

void dfs (int s)
{
    if (!mp[arr[s]])
        res.push_back(s);
    mp[arr[s]]++;
    visited[s] = 1;
    for (auto v: adj[s]) {
        if (!visited[v])
            dfs(v);
    }
    mp[arr[s]]--;

}


void solve ()
{
    ans = 0;
    bool ok = false;
    int n,m,k,q;  std::cin>>n;
    for (int i = 1; i < n+1;++i) {
        std::cin>>arr[i];
    }
    for (int i = 1; i < n;++i) {
        int u,v;
        std::cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1);
    sort(all(res));
    for (auto v: res)
        cout<<v<<'\n';
}
void sol ()
{
    //test
}

int main ()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    auto begin = std::chrono::high_resolution_clock::now();

    //cout << setprecision(15) << fixed;
    int testcases = 1;  
    for (int t = 0; t < testcases; ++t) {
        //cout<<"Case #"<<t+1<<": ";
        solve();
    }

		auto end = std::chrono::high_resolution_clock::now();
		cerr << setprecision(4) << fixed;
	    cerr << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll> ;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s1,n) for (ll i=(s1);i<(ll)(n);i++)
#define rrep(i,a,b) for (ll i=(a);i>=(ll)(b);i--)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define pb push_back
const ll inf=1LL<<60;
ll min(ll a,ll b) {return a>=b ? b:a;}
ll max(ll a,ll b) {return a>=b ? a:b;}
template<typename T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<typename T>bool chmin(T &a, const T &b) {if (b<a) {a=b; return 1;} return 0;}
//const ll mod=1000000007LL;
//const ll mod=998244353LL;
ll n;
vector<ll> G[100009];
ll c[100009];
ll C[100009];
vector<ll> d;
void dfs(ll st,ll prev){
    if (C[c[st]]==0){
        d.pb(st+1);
    }
    C[c[st]]++;
    for (ll i:G[st]){
        if (i==prev) continue;
        dfs(i,st);
    }
    C[c[st]]--;
}
int main(){
    fastio;
    cin >> n;
    rep(i,n) cin >> c[i];
    rep(i,n-1){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(0,-1);
    sort(all(d));
    for (ll i:d){
        cout << i << "\n";
    }
}