#include<bits/stdc++.h>
using namespace std;
 
#define mp          make_pair
#define pb          push_back
#define pf          push_front
#define ff          first
#define ss          second
#define all(x)      x.begin(),x.end()
#define rall(x)     x.rbegin(),x.rend()
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b))/gcd((a),(b))
#define endl        "\n"
#define pi          3.14159265358979323846
#define inf         1000000000
#define setbits(x)  __builtin_popcountll(x)
#define ordered_set    tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
typedef long long ll;
typedef long double ld;
 
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
const int N = 1e5+50;
const ll mod = 1e9+7;
const ll INF = 1e18;
 
// int dx[9]={-1,-1,-1,0,1,1,1,0,0};
// int dy[9]={-1,0,1,1,1,0,-1,-1,0};
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
 
bool compare(const pair<ll, ll>&i, const pair<ll, ll>&j) 
{ 
    return i.second < j.second; 
}
 
ll fact[N];
vector<bool> is_prime(100000,true);
vector<int>prime;
 
void pre()
{
    fact[0]=1;
    for(ll i=1;i<N;i++)
    {
        fact[i]=i*fact[i-1];
        fact[i]%=mod;
    }
}
 
ll modexp(ll x,ll n)
{
    ll r=1;
    while(n){
        if(n&1)
            r=(r*x)%mod;
 
        x=(x*x)%mod;
        n>>=1;
    }
    return r%mod;
}
 
ll modinv(ll x)                
{
    return modexp(x,mod-2);
}
 
ll ncr(ll n,ll r)
{
    if(n<r)
        return 0;
 
    ll ans=(fact[n]%mod * modinv(fact[r])%mod * modinv(fact[n-r])%mod)%mod;
    return ans;
}

ll exp(ll x,ll n)
{
    ll r=1;
    while(n){
        if(n&1)
            r=(r*x);
 
        x=(x*x);
        n>>=1;
    }
    return r;
}

int n;
vector<int>C(N);
vector<int>adj[N];
bool vis[N];
map<int,int>m;
int ver;

vector<int>ans;

void dfs(int x){
    vis[x]=1;
    if(m[C[x]]==0)
        ans.pb(x);
    m[C[x]]++;
    for(auto ch:adj[x]){
        if(!vis[ch]){
            dfs(ch);
        }
    }
    m[C[x]]--;
}

void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>C[i];
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(1);
    sort(ans.begin(),ans.end());
    for(auto x:ans)
        cout<<x<<endl;
    return ;
}
 
int32_t main()
{
    fio
 
    // #ifdef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
 
    // pre();
    int t=1;
    // cin>>t; 
    for(int i=0;i<t;i++)
    {
        solve();
    }
    return 0;
}
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








std::set<int> dfs(int cur, int prv, std::vector<int> &C, std::set<int> &c, std::vector<std::vector<int>> &G){
    std::set<int> rt;
    if(c.find(C[cur]) == std::end(c)) rt.insert(cur);
    c.insert(C[cur]);
    for(auto v: G[cur]){
        if(v == prv) continue;
        std::set<int> b{dfs(v, cur, C, c, G)};
        if(b.size() > rt.size()) swap(b, rt);
        for(auto e: b){
            rt.insert(e);
        }
    }
    if(rt.find(cur) != std::end(rt)) c.erase(C[cur]);
    return rt;
}

int main(){
    int N; std::cin >> N;
    std::vector<int> C(N);
    for(auto &e: C) std::cin >> e;
    std::vector<std::vector<int>> G(N);
    {
        int A, B;
        for(int i{0}, i_len{N-1}; i < i_len; ++i){
            std::cin >> A >> B;
            G[--A].push_back(--B);
            G[B].push_back(A);
        }
    }
    std::set<int> c;
    std::set<int> ans{dfs(0, NIL, C, c, G)};
    for(auto e: ans){
        std::cout << e+1 << "\n";
    }
    return 0;
}
