#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
struct Edge {
    int to;
    int cost;
    Edge(int t, int c) : to(t), cost(c) {}
};
using edge = struct {
    long long to;
    long long cost;
};
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int cnt[101010];
bool good[101010];

void dfs(const Graph& g, int c, int parent, const vector<int>& C) {
    if (cnt[C[c]] == 0) good[c] = true;
    cnt[C[c]]++;
    for (auto next_v : g[c]) {
        if (next_v == parent) continue;
        dfs(g, next_v, c, C);
    }
    cnt[C[c]]--;
}
int main() {
    int N;
    cin >> N;
    vector<int> C(N + 1);
    rep(i, N) cin >> C[i + 1];
    Graph g(N + 1);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(g, 1, -1, C);
    rep(i, N) if (good[i + 1]) cout << i + 1 << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void dfs(int i, int p, vector<int> &colors, vector<vector<int>> &adj_list, set<int> &used_color, vector<bool> &ans) {
  bool add_color;
  if (used_color.count(colors[i])) {
    add_color = false;
    ans[i] = false;
  } else {
    add_color = true;
    used_color.insert(colors[i]);
  }
  if (i == 0) {
    for (int c : adj_list[0]) {
      dfs(c, 0, colors, adj_list, used_color, ans);
    }
  } else {
    if (adj_list[i].size() == 1) {
      if (add_color) {
        used_color.erase(colors[i]);
      }
      return;
    } else {
      for (int c : adj_list[i]) {
        if (c != p) {
          dfs(c, i, colors, adj_list, used_color, ans);
        }
      }
        if (add_color) {
          used_color.erase(colors[i]);
        }
    }
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  vector<vector<int>> adj_list(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    adj_list[a].emplace_back(b);
    adj_list[b].emplace_back(a);
  }

  set<int> used_color;
  vector<bool> ans(n, true);
  
  dfs(0, -1, c, adj_list, used_color, ans);

  for (int i = 0; i < n; ++i) {
    if (ans[i]) {
      cout << i + 1 << endl;
    }
  }
}