/*
	Author:Frozencode
*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pii;
const ll maxn = 100010;
const ll INF = 2147483647;
ll n, c[maxn], cnt, res[maxn], x, y;
bool vis[maxn];
ll col[maxn];
vector <ll> e[maxn];
void dfs(ll tem){
	vis[tem] = 1;
	if(!col[c[tem]])res[++cnt] = tem;
	col[c[tem]]++;
	for(int i = 0; i < e[tem].size(); i++){
		if(!vis[e[tem][i]])dfs(e[tem][i]);
	}
	col[c[tem]]--;
}
int main()
{ 
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++)cin >> c[i];
	for(int i = 1; i < n; i++){
		cin >> x >> y;
		e[x].pb(y);
		e[y].pb(x);
	}
	dfs(1);
	sort(res + 1, res + cnt + 1);
	for(int i = 1; i <= cnt; i++)cout << res[i] << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end());reverse(v.begin(),v.end());}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}

ll N;
vector<ll> p;
vector<ll> c(1e5);
vector<ll> ans,seen;
vector<vector<ll>> G;

void DFS(int a){
	seen[a]=1;
	if(c[p[a]]==-1){
		ans.push_back(a);
		c[p[a]]=a;
	}
	for(auto x:G[a]){
		if(seen[x]==0) DFS(x);
	}
	if(c[p[a]]==a) c[p[a]]=-1;
}

//Cとかで出てみたい
int main() {
	cin>>N;
	rep(i,N){
		ll a;
		cin>>a;
		a--;
		p.push_back(a);
	}
	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);
	}
	seen.resize(N);
	rep(i,1e5) c[i]=-1;
	DFS(0);
	rep(i,ans.size()) ans[i]++;
	So(ans);
	print_tate(ans);
}

