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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define all(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0)  )
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}
const int N=1E5+1;
int c[N];
vi g[N];
int cnt[N];
int n;
int good[N];
void dfs(int node, int p=-1){
    if (++cnt[c[node]]==1) good[node+1]=1;
    for(int v:g[node]){
        if (v!=p){
            dfs(v,node);
        }
    }
    --cnt[c[node]];
}
int main() {
    READ(0);
    cin>>n;
    FOR(i,n) cin>>c[i];
    FOR(i,n-1){
        int u,v;cin>>u>>v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0);
    for(int i=1;i<=n;++i) if (good[i]) cout << i << " ";
    return 0;
}


#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;
}