#include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
#define REP_sz(i,s) for(int i=0;i<s.size();i++)
#define gcd(a,b) __gcd(a,b)
#define RE return
#define FILL(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) (int)a.size()
#define V vector
#define ld long double
#define viit(a) vector<int>::iterator a
#define IT iterator
#define SET setprecision
#define FOR(i,a,n) for(int i=a;i<=(n);i++)
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
#define mod1 1000000007
#define mod2 998244353
#define infmod 9223372036854775783
#define tc int t;cin>>t;while(t--)solve();
#define over(x) {cout<<x<<endl;return;}
#define intsz(x) (int)sz(to_string(x))
using namespace std;
int n;
int c[100005];
vector<int>ver[100005];
bool flag[100005];
V<int>ans;
void dfs(int x,int fx){
	if(!flag[c[x]])
	ans.pb(x+1);
	bool f=flag[c[x]];
	flag[c[x]]=1;
	REP_sz(i,ver[x])if(ver[x][i]!=fx)dfs(ver[x][i],x);
	flag[c[x]]=f;
}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	cin>>n;
	REP(i,0,n)cin>>c[i];
	REP(i,0,n-1){
		int a,b;
		cin>>a>>b;
		ver[a-1].pb(b-1);
		ver[b-1].pb(a-1);
	}
	dfs(0,-1);
	SO(ans);
	REP(i,0,ans.size())cout<<ans[i]<<endl;
    return 0;
}

#include <bits/stdc++.h>
#include <functional>
#include<stdio.h>
using namespace std;
#define ll       	long long int
#define dd      	long double
#define pb          push_back
#define pf          push_front
#define pi         pair<ll,ll>
#define vi          vector<ll>
#define vpi        vector<pi>
#define mi          map<ll,ll>
#define um          unordered_map<ll,ll>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x         first
#define y         second
#define sz(x)       (ll)x.size()
#define u        	'\n'
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define rf(s)       for(auto &c : s)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++) //use Iterator
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
//#define M           998244353 
#define yes       cout<<"Yes"<<'\n';
#define no        cout<<"No"<<'\n';
#define C         continue;
#define pa(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
#define pv(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<'\n'
#define pvp(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i.x<<","<<i.y<<" | "; cout<<'\n'
#include <ext/pb_ds/tree_policy.hpp>     
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>     
using namespace __gnu_pbds;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define fbo find_by_order
#define ook order_of_key
const ll MAXN = 1e7+1;
const ll N = 100;
const dd eps = 1e-14;
 
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); } 
ll power(ll x, ll y) 
{ 
    ll res=1;
	x%=M;   
    while(y>0) 
    { 
        if(y&1) 
        res=res*x; 
        res%=M;
        y=y>>1; 
        x=x*x;  
        x%=M;
    } 
    return res; 
}

set<ll>s;
map<ll,ll>m;
vector<vi>v;
vi a;
void dfs(ll n,ll p)
{
	ll t=a[n];
	if(m[t]==0)
	{
		s.insert(n);
		m[t]=n;
	}
	for(auto i:v[n])
	{
		if(i!=p)
		dfs(i,n);
	}
	t=a[n];
	if(m[t]==n)
	m[t]=0;
}
signed main()
{
	tezz
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n,i;
		cin>>n;
		a=vi(n+1);
		fo(i,1,n+1)
		{
			cin>>a[i];
		}
		v=vector<vi>(n+1);
		fo(i,0,n-1)
		{
			ll a,b;
			cin>>a>>b;
			v[a].pb(b);
			v[b].pb(a);
		}
		dfs(1,-1);
		for(auto i:s)
		cout<<i<<u;
	}
	return 0;
} 