#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> cs(n), as(n - 1), bs(n - 1);
	for (auto &&c : cs)
	{
		cin >> c;
		c--;
	}
	for (int64_t i = 0; i < n - 1; i++)
	{
		cin >> as[i] >> bs[i];
		as[i]--;
		bs[i]--;
	}

	vector<vector<int64_t>> g(n);
	for (int64_t i = 0; i < n - 1; i++)
	{
		g[as[i]].emplace_back(bs[i]);
		g[bs[i]].emplace_back(as[i]);
	}

	set<int64_t> ans;

	vector<int64_t> cnt(100'000, 0);

	auto dfs = [&](auto &&f, int64_t now, int64_t par = -1) -> void {
		if (cnt[cs[now]] == 0)
		{
			ans.insert(now);
		}

		cnt[cs[now]]++;

		for (auto &&nxt : g[now])
		{
			if (nxt == par)
			{
				continue;
			}

			f(f, nxt, now);
		}

		cnt[cs[now]]--;
	};

	dfs(dfs, 0);

	for (auto &&x : ans)
	{
		cout << (x + 1) << endl;
	}

	return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll mod = 998244353;
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
ll modinv(ll a) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }u %= mod; if (u < 0) u += mod; return u; }

vector<vector<int>> G;
vector<int> c, used;
int t[100001];
vector<int> good;
void dfs(int v) {
	if (used[v] == 1)return;
	used[v] = 1;
	if (t[c[v]] == 0)good.push_back(v + 1);
	t[c[v]]++;
	for (auto u : G[v])dfs(u);
	t[c[v]]--;
}
int main() {
	int n;
	cin >> n;
	G.resize(n);
	c.resize(n);
	used.resize(n);
	rep(i, 0, n)cin >> c[i];
	rep(i, 0, n - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0);
	sort(all(good));
	for(auto v : good)printf("%d\n", v);
	return 0;
}