#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}
const int mx=1e5+5;
vector<int> adj[mx];
int vis[mx];
int good[mx];
int c[mx+1];
multiset<int> s;
void dfs(int node,int depth){
    vis[node]=1;
    if(!s.count(c[node])){
    	//cout<<node;
       good[node]=1;
       
    }
    s.insert(c[node]);
    
    for(int next:adj[node]){
        if(!vis[next]){
          dfs(next,depth+1);
        }
    }
    auto it=s.find(c[node]);
    
    s.erase(it);
       
}


int main() {
   fast();
   int n;
   cin>>n;
   
   for(int i=1;i<=n;i++){
    cin>>c[i];
   }
   for(int i=1;i<=n-1;i++){
    int a,b;
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
   }
   set<int> s;
   
   dfs(1,1);
   vector<int> ans;
   for(int i=1;i<=n;i++){
    if(good[i]){
      cout<<i<<"\n";
    }
   }





}
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int n;
vvi G;
vi color,used,ans;
void dfs(int a,int p){
	if(!used[color[a]])ans[a]=true;
	used[color[a]]++;
	rep(i,G[a].size())if(G[a][i]-p){
		dfs(G[a][i],a);
	}
	used[color[a]]--;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	color=ans=vi(n);
	used=vi(100100);
	rep(i,n)cin>>color[i];
	G=vvi(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	dfs(0,-1);

	rep(i,n)if(ans[i])cout<<i+1<<endl;
}
