#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<ll>>adj(200010);
ll vis[200010];
vector<ll>ans;
map<ll,ll>mp;
ll c[200010];
void dfs(ll u)
{
    vis[u]=1;
    mp[c[u]]++;
    for(auto it=adj[u].begin();it!=adj[u].end();it++)
    {
        if(!vis[*it])
        {
            if(mp[c[*it]]==0)
                 ans.push_back(*it);
            dfs(*it);
        }
    }
    mp[c[u]]--;

}
int main()
{
    ll n;
    cin>>n;
    ll i;
    for(i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    for(ll i=0;i<n-1;i++)
    {
        ll x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(1);
    ans.push_back(1);
    sort(ans.begin(),ans.end());
    for(i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
}

#include "bits/stdc++.h"

using namespace std;

#define pb push_back

#define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i))

vector<vector<int>> adj(100001);
vector<int> color(100001);
vector<bool> good(100001);

void dfs(int n, multiset<int>& s, int m = -1) {
    if (!s.count(color[n])) {
        good[n] = true;
    }
    s.insert(color[n]);
    for (int p : adj[n]) {
        if (p != m) {
            dfs(p, s, n);
        }
    }
    s.erase(s.find(color[n]));
}

void solve() {
    int n; cin >> n;
    ice (i, 0, n) {
        cin >> color[i];
    }
    ice (i, 0, n - 1) {
        int a, b; cin >> a >> b; a--; b--;
        adj[a].pb(b); adj[b].pb(a);
    }
    multiset<int> s;
    dfs(0, s);
    ice (i, 0, n) {
        if (good[i]) {
            cout << i + 1 << '\n';
        }
    }
}

int main() {
    solve();
}