#include <bits/stdc++.h>

#define E (edges[i])

using namespace std;

const int MAXN = 1e5 + 10;

struct Edge{ int to, next; } edges[MAXN << 1]; int head[MAXN], ecnt = 0;
void add_edge(int x, int y) { ecnt++; edges[ecnt].to = y, edges[ecnt].next = head[x]; head[x] = ecnt; }

int n, col[MAXN]; bool m[MAXN];
priority_queue<int> res;

void dfs(int x, int fa)
{
	for (int i = head[x]; i; i = E.next)
	{
		if (E.to == fa) continue;
		bool f = m[col[E.to]]; if (!f) res.push(-E.to);
		m[col[E.to]] = true; dfs(E.to, x); m[col[E.to]] = f;
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", col + i);
	for (int i = 1, x, y; i < n; i++) scanf("%d%d", &x, &y), add_edge(x, y), add_edge(y, x);
	res.push(-1), m[col[1]] = 1;
	dfs(1, 0);
	while (res.size()) printf("%d\n", -res.top()), res.pop();
}
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

vector<int>c;
vector<vector<int>>to;
vector<int>cnt;
vector<int>ans;

void dfs(int v, int p = -1) {//デフォルト引数-1
	if (cnt[c[v]] == 0) ans.push_back(v+1);
	cnt[c[v]]++;
	for (int u : to[v]) {
		if (u == p) continue;//親を探索対象にしないようにする
		dfs(u, v);
	}
	cnt[c[v]]--;
}

int main() {
	int n;
	cin >> n;
	c = vector<int>(n);
	rep(i, n) cin >> c[i];
	to.resize(n);
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	cnt = vector<int>(100010);
	dfs(0);
	sort(ans.begin(), ans.end());
	for (int v : ans) cout << v << endl;
}
