#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <numeric>
using namespace std;

using ll = long long;

#define For(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFor(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
#define co(a) cout<<a<<endl
#define Sort(a) sort((a).begin(),(a).end())
#define Rev(a) reverse((a).begin(),(a).end())
#define Unique(a) (a).erase(unique((a).begin(), (a).end()),(a).end())
#define cfs(a) cout<<fixed<<setprecision(a) 

ll N;

vector<bool> ans(100005);
vector<ll> check(100005);
void dfs(vector<ll> &coler,vector<vector<ll>> &ki,ll now, ll bef) {
	if (0 == check[coler[now - 1]]) {
		ans[now] = true;
	}
	check[coler[now - 1]]++;
	For(i, 0, ki[now].size()) {
		if (ki[now][i] != bef) {
			dfs(coler, ki, ki[now][i], now);
		}
	}
	check[coler[now - 1]]--;
}

int main() {
	//ll N;
	cin >> N;
	vector<ll> coler(N); //colerだけ0から
	For(i, 0, N) {
		cin >> coler[i];
	}
	vector<vector<ll>> ki(N+1, vector<ll>(0));
	ll A, B;
	For(i, 0, N - 1) {
		cin >> A >> B;
		ki[A].push_back(B);
		ki[B].push_back(A);
	}
	check[coler[0]] = 1;
	ans[1] = true;
	For(i, 0, ki[1].size()) {
		dfs(coler, ki, ki[1][i], 1);
	}
	For(i, 0, N + 1) {
		if (ans[i]) {
			co(i);
		}
	}
}
#include <bits/stdc++.h>

#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
//const int mod = 998244353;
const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e6 + 10;
const int N = 6e6 + 100;

int c[maxn];
vector<int > e[maxn];
int vis[maxn];
int g[maxn];

void dfs(int x,int fa){
    if (vis[c[x]]==0) g[x]=1;
    vis[c[x]]++;
    for(auto v:e[x]) if (fa!=v) dfs(v,x);
    vis[c[x]]--;
}

void solve() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>c[i];
    for (int i = 0; i < n - 1; ++i) {
        int u,v;
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(1,0);
    for (int i = 1; i <=n; ++i)
        if (g[i]) cout<<i<<"\n";
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();//cout<<"\n";
    }
    return 0;
}