// Problem: E - Unique Color
// Contest: AtCoder - AtCoder Beginner Contest 198
// URL: https://atcoder.jp/contests/abc198/tasks/abc198_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define it insert
#define pob pop_back
#define pub push_back
#define emb emplace_back
#define all(v) (v).begin(), (v).end()
#define mkp(a, b) make_pair(a, b)
using LL = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
const double EPS = 1e-6;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 7;

int h[N], e[2 * N], ne[2 * N], idx;
int color[N], vt[N], cnt[N];
int n;
int ans[N], m;

void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }

void dfs(int u) {
    cnt[color[u]] += 1;
    vt[u] = 1;
    if (cnt[color[u]] == 1) ans[m++] = u;
    for (int i = h[u]; i != -1; i = ne[i]) {
        int v = e[i];
        if (!vt[v]) dfs(v);
    }
    cnt[color[u]] -= 1;
}

int main() {
    memset(h, -1, sizeof h);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> color[i];
    for (int i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        add(x, y), add(y, x);
    }
    dfs(1);
    sort(ans, ans + m);
    for (int i = 0; i < m; ++i) cout << ans[i] << '\n';
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

const int MAX_N = 1e5 + 10;
int n;
vi color(MAX_N);
vi cnt(MAX_N, 0);
vi ans(MAX_N, false);
vvi to(MAX_N);
void dfs (int now, int p) {
    for (int nxt : to[now]) {
        if (nxt == p) continue;
        if (cnt[color[nxt]] == 0) ans[nxt] = true;
        cnt[color[nxt]]++;
        dfs(nxt, now);
        cnt[color[nxt]]--;
    }
}

int main () {
    cin >> n;
    rep(i, n) cin >> color[i];
    rep(i, n-1) {
        int a, b; cin >> a >> b, a--, b--;
        to[a].eb(b);
        to[b].eb(a);
    }
    ans[0] = true;
    cnt[color[0]]++;
    dfs(0, -1);
    rep(i, n) if (ans[i]) cout << i+1 << endl;
    return 0;
}