#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T> 
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

ll n;
vector<ll>c;
Graph g;

multiset<ll>st;
vector<ll>ans;

void dfs(ll v,ll p){
	auto it = st.find(c[v]);
	if(it==st.end()){
		ans.push_back(v);
	}
	st.insert(c[v]);
	for(auto x:g[v]){
		if(x==p)continue;
		dfs(x,v);
	}
	st.erase(st.find(c[v]));
	return;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin >> n;
	c.resize(n);
	rep(i,n)cin>>c[i];
	g.resize(n);
	rep(i,n-1){
		ll a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0,-1);
	sort(ans.begin(),ans.end());
	rep(i,ans.size()){
		cout << ans[i]+1 << endl;
	}

	return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int arr[100005];
bool vis[100005];
vector<int>vec;
multiset<int>ms;
void dfs(int node,vector<vector<int>>&v)
{
    vis[node]=1;
    if(!ms.count(arr[node-1]))
        vec.push_back(node);
    ms.insert(arr[node-1]);
    for(int i=0;i<v[node].size();i++){
        if(!vis[v[node][i]])
            dfs(v[node][i],v);
    }
    ms.erase(ms.find(arr[node-1]));
}
int main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<vector<int>>v(n+5);
    for(int i=0; i<n-1; i++) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1,v);
    sort(vec.begin(),vec.end());
    for(auto it:vec)
        cout<<it<<"\n";
}
