#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int c[100010], cnt[100010], good[100010];
vector<int> e[100010];

void dfs(int now, int p = -1) {
	if (cnt[c[now]] == 0)
		good[now] = true;
	cnt[c[now]]++;
	for (auto to : e[now]) if (to != p)
		dfs(to, now);
	cnt[c[now]]--;
}

int main() {
	int n; cin >> n;
	REP(i, n) cin >> c[i];
	REP(i, n-1) {
		int a, b; cin >> a >> b;
		e[--a].push_back(--b);
		e[b].push_back(a);
	}
	dfs(0);
	REP(i, n) if (good[i])
		cout << i+1 << '\n';
    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define SORT(v) sort(all(v))
#define int long long
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"

using namespace std;

void oj()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifndef ONLINE_JUDGE  
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
}

vector<int>v[200005];
int n;
vector<int>color;
set<int>st;
vector<int>ans;
void dfs(int x, int par)
{
  bool ok = false;
  if(st.find(color[x]) == st.end())
  {
    st.insert(color[x]);
    ans.pb(x);
    ok = true;
  }
  for(auto el : v[x])
  {
    if(el != par)
      dfs(el, x);
  }
  if(ok)
    st.erase(color[x]);
}
void solve()
{
  cin>>n;
  color = vector<int>(n + 1);

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

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

  dfs(1, 0);
  SORT(ans);
  for(auto el : ans)
    cout<<el<<endl;
}
signed main()
{
  oj(); 
  // int t; cin>>t;
  // while(t--)
    solve();

  return 0;
}
