#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
#include <unordered_map>

//  using declaration, alias
using llong = long long;
using ldouble = long double;

// constant
constexpr auto INF_LL = 0x7FFFFFFFFFFFFFFFLL;
// constexpr auto MOD = 0LL;

namespace io {
  template <class T = llong> auto in() {T a;std::cin >> a;return a;}
  template <class T = llong> auto in(int n) {std::vector<T> v(n); for (auto& vi : v) vi = in<T>(); return v;}
  template <class T = llong> auto in(int n, int m) {std::vector<std::vector<T>> v(n, std::vector<T>(m)); for (auto& vi : v) for (auto& vij : vi) vij = in<T>(); return v;}
  template <size_t... S, class... T> void in_var(std::index_sequence<S...>, std::tuple<T...>& t) {std::initializer_list<int>{(std::get<S>(t) = in<T>(), 0)...};}
  template <size_t... S, class... T> void in_vec(std::index_sequence<S...>, std::tuple<std::vector<T>...>& t) {std::initializer_list<int>{(std::get<S>(t).emplace_back(in<T>()), 0)...};}
  template <class T, class U, class... V> auto in() {std::tuple<T, U, V...> t; in_var(std::index_sequence_for<T, U, V...>(), t); return t;}
  template <class T, class U, class... V> auto in(int n) {std::tuple<std::vector<T>, std::vector<U>, std::vector<V>...> t; for (auto i = 0; i < n; i++) in_vec(std::index_sequence_for<T, U, V...>(), t); return t;}
  template <int N, class T = llong, class... U> auto in() {if constexpr (N > 1) return in<N - 1, T, T, U...>(); else return in<T, U...>();}
  template <int N, class T = llong, class... U> auto in(int n) {if constexpr (N > 1) return in<N - 1, T, T, U...>(n); else return in<T, U...>(n);}
  template <class T> void out(T a) {std::cout << a << "\n";}
  template <class T, class... U> void out(T a, U... b) {std::cout << a << " "; out(b...);}
}

void dfs(llong node, llong node_b, std::vector<llong>& color, std::unordered_map<llong, std::vector<llong>>& graph, std::vector<llong>& count, std::vector<llong>& result) {
  if (count[color[node - 1] - 1] == 0) result.emplace_back(node);
  count[color[node - 1] - 1]++;
  for (auto to : graph[node]) {
    if (to != node_b) dfs(to, node, color, graph, count, result);
  }
  count[color[node - 1] - 1]--;
}

int main() {
  // input
  auto N = io::in();
  auto C = io::in(N);
  auto [A, B] = io::in<2>(N - 1);

  // solve
  std::unordered_map<llong, std::vector<llong>> graph;
  for (auto i = 0LL; i < N - 1; i++) {
    graph[A[i]].emplace_back(B[i]);
    graph[B[i]].emplace_back(A[i]);
  }
  std::vector<llong> count(100000, 0LL);
  std::vector<llong> result;
  dfs(1, 0, C, graph, count, result);
  std::sort(result.begin(), result.end());

  // output
  for (auto r : result) io::out(r);
}
#include <bits/stdc++.h>
using namespace std;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A, class B> inline void chmod(A &a, const B b) { a = a%b; return; }

void dfs(int node);

int n, c[100000], a, b, pal[100000], pass[100000];
vector<int> vec[100000];

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

  dfs(0);
  for (int i=0; i<n; i++) {
    if (c[i] > -1) {
      cout << i+1 << endl;
    }
  }
  return (0);
}

void dfs(int node) {
  if ( pass[node] == 0 ) {
    pass[node] = 1;
    pal[c[node]]++;    
    for (int i=0; i<vec[node].size(); i++) {
      dfs(vec[node][i]);
    }
    pal[c[node]]--;
    if ( pal[c[node]] > 0 ) {
      c[node] = -1;
    }
  }
  return; 
}