#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl '\n';
#define sz(s) int(s.size())
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()), ((v).rend()) 
#define mem(x,y) memset(x,y,sizeof(x))
#define Ceil(x,y)  ((x+y-1)/y)
typedef long long ll;
typedef double dl;
using namespace std;
void Selim()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
/***************************************************/
vector<vector<int>>adjList;
vector<int>color, dis, ok;
bool vis[int(1e5 + 10)];
set<int>st;
void DFS(int node){
	vis[node] = 1;
	if (!ok[color[node]]){
		st.insert(node);
	}
	ok[color[node]]++;
	for (auto child : adjList[node]){
		if (vis[child])continue;
		DFS(child);
	}
	ok[color[node]]--;
}
void solve(){
	int n;
	cin >> n;
	adjList.resize(1e5 + 5);
	color.resize(1e5 + 5);
	dis.resize(n + 1, 1e9);
	ok.resize(1e5 + 5, 0);
	dis[1] = 0;
	for (int i = 1; i <= n; i++){
		cin >> color[i];
	}
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
	}
	DFS(1);
	st.insert(1);
	for (auto it : st){
		cout << it << endl;
	}
}
int main()
{
	Selim();
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acosl(-1.0);
const long double EPS=1e-10;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[8] = {0,0,1,-1,1,1,-1,-1};
const int dy[8] = {1,-1,0,0,1,-1,1,-1};
template<typename T>void vecout(const vector<T> &a){int n=a.size();rep(i,0,n)cout<<a[i]<<(i==n-1 ? "":" ");cout<<endl;}

int f(vin &a,int x){
  int ret=0;
  auto it=upper_bound(all(a),x);
  ret=it-a.begin();
  return ret;
}

vvin cdp;//positive
vvin cdn;//negative
vin c;

vector<vector<int>> g;
vector<int> in,out;
int counter;

void euler_tour(int now,int par=-1){
 cdp[c[now]].pb(counter);
 in[now]=counter++;
  
 for(int to:g[now])if(to!=par)euler_tour(to,now);
  
 cdn[c[now]].pb(counter);
 out[now]=counter++;
}


int main(){//cout<<fixed<<setprecision(20);
  cdp.resize(110000);
  cdn.resize(110000);
  int n;
  cin>>n;
  c.resize(n);
  rep(i,0,n)cin>>c[i];
  g.resize(n);
  in.resize(n);
  out.resize(n);
  rep(i,0,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  
  euler_tour(0);
  
  rep(i,0,n){
   int pc=f(cdp[c[i]],in[i]);
   int nc=f(cdn[c[i]],in[i]);
   if(pc-nc==1)cout<<i+1<<endl; 
  }
}