#include <bits/stdc++.h>

using namespace std;
#define ll long long

const ll OO = 0x3f3f3f3f;
const ll mod =   1e9 + 7;
const double pi = 3.14159265359;

//freopen("window.in", "r", stdin);
//freopen("output.out", "w", stdout);
void skrrrt() {
    ios_base::sync_with_stdio(0), cin.tie(0);
}
//###############################Spaggetti############################
const int N=100009;
int color[N];
vector<vector<int>>g(N);
int n;
map<int,int>mp;
vector<int>ans;
bool vis[N];
void dfs(int node){
    vis[node]=1;
    if(mp[color[node]]==0)ans.push_back(node);
    mp[color[node]]++;
    for(auto child:g[node]){
        if(!vis[child]){
            dfs(child);
        }

    }
    mp[color[node]]--;
}
int main(){
    skrrrt();
    cin>>n;
    for(int i=1;i<=n;i++)cin>>color[i];
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    sort(ans.begin(),ans.end());
    for(auto i:ans)
        cout<<i<<"\n";

}
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

const int mod = 1000000007;
// const int mod = 998244353;


int n;
vi c;
vvi g;
map<int, int> mp;
vector<bool> ans;
vi used;

void dfs(int v) {
  // cout << v << endl;
  used[v] = 1;
  if (mp[c[v]]) ans[v] = false;
  mp[c[v]]++;
  for (int e : g[v]) {
    if (used[e]) continue;
    dfs(e);
  }
  mp[c[v]]--;
}

int main() {
  cin >> n;
  c.resize(n);
  g.resize(n);
  used.resize(n);
  ans = vector<bool>(n, true);
  rep(i,n) cin >> c[i];
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0);
  rep(i, n) if (ans[i]) cout << i+1 << endl;
  // for (auto x : mp) printf("%d : %d\n", x.first, x.second);
}