///

#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fodec(i,a,b) for(int i=a;i>b;i--)
#define sz(v) int(v.size())
#define len(s) s.length()
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vvll vector<vector<ll>>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define piii pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define bit_cnt(x) __builtin_popcount(x)
#define fastio ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fileio freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define inf 1e9
const int MOD = 1e9+7;

int n;
vvi adj;
vi cc;
vi ans;

unordered_map<int,bool> uu;

void solve(int s,int par){
    bool f=false;
    if(!uu[cc[s]]){
        f=true;
        ans.pb(s);
        uu[cc[s]]=true;
    }
    for(auto&x:adj[s]){
        if(x==par) continue;
        solve(x,s);
    }
    if(f) uu[cc[s]]=false;
}

int main(){
    cin>>n;
    cc.assign(n,-1);
    fo(i,0,n) cin>>cc[i];
    adj.assign(n,vector<int>());
    fo(i,0,n-1){
        int x,y;
        cin>>x>>y;
        x--; y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    ans.clear();
    uu.clear();
    solve(0,-1);
    sort(all(ans));
    for(auto&it:ans) cout<<it+1<<endl;
}

#include "bits/stdc++.h"


#pragma GCC optimize("Ofast")


using namespace std;

#define endl            "\n"
#define all(v)          v.begin(), v.end()
#define debug(x)        cout << #x << " is " << x << endl
#define isOdd(n)        (n&1)
#define pow(n, m)       (ll)powl(n, m)
#define Unique(x)       x.erase(unique(all(x)), x.end())
#define clr(x, last)    memset(x, last, sizeof(x))

using ll = long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<ll, int>;
using tii = tuple<int, int, int>;

const int N = 1e5 + 5, M = 2e5 + 5;

int ne, head[N], nxt[M], to[M], color[N];

void initGraph(int n){
    memset(head, -1, n * sizeof(head[0]));
    ne = 0;
}

void addEdge(int f, int t){
    to[ne] = t;
    nxt[ne] = head[f];
    head[f] = ne++;
}

void addBidirectedEdge(int u, int v){
    addEdge(u, v);
    addEdge(v, u);
}

int f[N];
vector<int> ans;

void dfs(int u, int par){
    if(!f[color[u]]) ans.push_back(u + 1);
    f[color[u]]++;
    for (int k = head[u]; ~k; k = nxt[k]) {
        int v = to[k];
        if(v == par) continue;
        dfs(v, u);
    }
    f[color[u]]--;
}

int main()
{

    ios_base::sync_with_stdio(0), cin.tie(0);

    int n; cin >> n;
    initGraph(n);

    for (int i = 0; i < n; ++i) {
        cin >> color[i];
    }
    for (int i = 0; i + 1 < n; ++i) {
        int u, v; cin >> u >> v;
        --u, --v;
        addBidirectedEdge(u, v);
    }

    dfs(0, -1);
    sort(all(ans));
    for(auto &i: ans)
        cout << i << endl;
    return 0;
}