#include <bits/stdc++.h>
using namespace std;
#define REP(i, e) for (int i = 0; i < (e); ++i)
#define REP3(i, b, e) for (int i = (b); i < (e); ++i)
#define RREP(i, b, e) for (int i = (b)-1; i >= e; --i)

struct Initializer {
  Initializer() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15) << std::boolalpha;
  }
} initializer;

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
  for (auto &x : vec) {
    os << x;
    if (&x != &vec.back()) os << ' ';
  }
  return os;
}

template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &pa) {
  return os << pa.first << ' ' << pa.second;
}

template <std::size_t N, typename... T>
std::ostream &print_tuple(std::ostream &os, const std::tuple<T...> &tup) {
  if constexpr (N != 1UL) {
    print_tuple<N - 1, T...>(os, tup);
    os << ", " << std::get<N - 1>(tup);
  } else {
    os << std::get<0>(tup);
  }
  return os;
}

template <typename... T>
std::ostream &operator<<(std::ostream &os, const std::tuple<T...> &tup) {
  os << '(';
  print_tuple<sizeof...(T), T...>(os, tup);
  return os << ')';
}

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &se) {
  os << '{';
  for (auto &x : se) {
    os << x;
    if (&x != &*se.rbegin()) os << ", ";
  }
  return os << '}';
}

template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &ma) {
  os << '{';
  for (auto &x : ma) {
    os << x.first << ": " << x.second;
    if (&x != &*ma.rbegin()) os << ", ";
  }
  return os << '}';
}

inline void print(void) {
  std::cout << '\n';
}

template <class T, class... U>
inline void print(const T &x, const U &...y) {
  std::cout << x;
  if (sizeof...(U) != 0) {
    std::cout << ' ';
  }
  print(y...);
}

int n;
map<int, int> ma;
vector<int> c;
vector<vector<int>> g;
vector<int> ans;

void rec(int par, int cur) {
  if (ma[c[cur]] == 1) ans.emplace_back(cur);

  for (auto nx : g[cur]) {
    if (nx == par) continue;
    ++ma[c[nx]];
    rec(cur, nx);
    --ma[c[nx]];
  }
}

int main() {
  cin >> n;
  c.resize(n);
  REP(i, n) cin >> c[i];
  g.resize(n);
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  ++ma[c[0]];
  rec(-1, 0);
  sort(ans.begin(), ans.end());
  REP(i, ans.size()) { print(ans[i] + 1); }

  return 0;
}

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops") 
 
 
#include<bits/stdc++.h>  
#define ll int64_t 
#define ff first  
#define ss second  
#define mkp make_pair 
#define pb push_back  
#define pf push_front  
#define inf 100000000
#define maxn 100005
#define mod  998244353
#define mod1 1000000009
 
using namespace std;   

int col[maxn];  

int colour[maxn]; 

vector<int>v[maxn];  
vector<int>ans; 

void dfs(int src,int par){  
   if(colour[col[src]]==0){  
     ans.push_back(src);
   }  
   colour[col[src]]++; 

   for(auto it:v[src]){  
    if(it==par) 
      continue; 
    dfs(it,src);
   } 

   colour[col[src]]--; 
}


void solve(){  
  int n; 
  cin>>n;   

  for(int i=1;i<=n;++i) 
      cin>>col[i];  

  int a,b; 

  for(int i=0;i<n-1;++i){
     cin>>a>>b; 
     v[a].pb(b); 
     v[b].pb(a); 
  } 

  dfs(1,-1);   


  sort(ans.begin(),ans.end()); 

  for(int i=0;i<ans.size();++i)  
     cout<<ans[i]<<'\n'; 





} 

 
int main(){     

  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
 
  #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);  
       freopen("output.txt","w",stdout); 
  #endif  
 
  solve();


      

return 0;  
 
}   





   
