#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
template<class A, class B>void tostring(pair<A, B>p) { cerr<<"(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template<class A>void tostring(A v) {int f = 1;string r = "{";for (auto& x : v) {if (!f) {r += ", ";}f = 0;r += to_string(x);}r += "}\n";cerr<<r;}
void _out() { cerr << endl; }template<typename H, typename... T> void _out(H h, T... t) { cerr << ' ' << h; _out(t...); }
void show() { cerr << endl; }template<typename H, typename... T> void show(H h, T... t) { cerr<<h<<' '; show(t...); }
#define see(...) cerr << "(" << #__VA_ARGS__ << "):", _out(__VA_ARGS__)
#define rep(i, l, r) for(int i=(int)(l);i<=(int)(r);i++)
#define per(i, r, l) for(int i=(int)(r);i>=(int)(l);i--)
#define all(x) (x).begin(), (x).end()
#define all1(x) (x).begin()+1, (x).end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
//#define int long long
typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp;
#define fi first
#define se second
const int N = 1e5+100;
//const int mod=1e9+7;
int h[N], e[2*N], ne[2*N],idx,col[N], bcol[N];
bool st[N];
vector<int>ans;
void add(int a, int b){
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}
void dfs(int u, int fa){
	if(!bcol[col[u]]){
		ans.pb(u);
	}
	bcol[col[u]] ++;
	for(int i = h[u]; i != -1; i = ne[i]){
		int j = e[i];
		if(j == fa)continue;
		dfs(j, u);
	}
	bcol[col[u]] --;
}
void solve() {
	memset(h, -1, sizeof h);
	int n;cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> col[i];
	}
	for(int i = 0; i < n - 1; i ++){
		int a, b;cin >> a >> b;
		add(a, b), add(b, a);
	}
	dfs(1, -1);
	sort(all(ans));
	rep(i, 0, ans.size() - 1)cout << ans[i] << endl;
}
signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("E:\\in.txt", "r", stdin);
#endif
	solve();
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(ll i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define ones(x) __builtin_popcount(x)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define dbg(x) cout << (#x) << " = " << x << " "
#define fini cout << "\n";
#define line cout << "-----------------------------------\n";
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef tree<
ll,
null_type,
less_equal<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
int read (){
    int x = 0, f = 1; char s = getchar();while (s < '0' || s > '9') {if (s == '-') f = -1; s = getchar();}
    while (s >= '0' && s <= '9') x = x * 10 + s - '0', s = getchar();
    return x * f; 
}
const ll M=2e5+7;
const ll N=1e6+7;
const ll inf=1e18;
const ll mod=1e9+7;
const ll mod2=998244353;

int n;
int c[M];
vi adj[M];
map<int,int> d;
vi ans;

void dfs(int u,int p){
	if (!d.count(c[u]) || d[c[u]] == 0) ans.pb(u);
	d[c[u]]++;

	for (int v : adj[u])
		if (v != p) dfs(v, u);

	d[c[u]]--;
}

void go(int ide){
	cin >> n;

	fp(i,1,n+1) cin >> c[i];

	fp(i,1,n){
		int a,b; cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}

	dfs(1, 1);
	sort(all(ans));

	for (int x : ans) cout << x << "\n";
}

int main(){
    fastio;
    int tst=1;
    // cin >> tst;
    // cout << fixed << setprecision(12);
 
    fp(i,0,tst) go(i+1);
 
    return 0;
}