#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 61;
const ll mod =998244353;


int n;
VI g[100005];
VI c(100005);
VB used_color(100005, false);
VI ans;

VB used(100005, false);

void dfs(int pre, int now) {
	for (int i : g[now]) {
		//cout << i << endl;
		if (used[i])continue;
		//if (i == pre)continue;
		bool check = false;
		if (used_color[c[i]])check = true;
		//cout << i << endl;
		used_color[c[i]] = true;
		if(!check)ans.push_back(i);
		used[i] = true;
		dfs(now, i);
		if(!check)used_color[c[i]] = false;
	}
}


int main() {

	cin >> n;
	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);
	}
	used_color[c[0]] = true;
	used[0] = true;
	dfs(-1, 0);



	sort(ALL(ans));
	cout << 1 << endl;
	for (int i : ans) {
		cout << i + 1 << endl;
	}


}
/*

  AUTHOR:    nit1n
  CREATED:   12.04.2021 22:51:16

*/
#include<bits/stdc++.h>
#define int long long
using namespace std ;
const int N = 1e5 +5 ; 
vector<int> gr[N] ; 
vector<int> a(N) , ans; 
void dfs(int i , int prev , map<int,int>& mp){
	
	if(mp[a[i]] == 0){
		ans.push_back(i) ; 
	}
	mp[a[i]]++ ; 
	for(auto & j : gr[i]){
		if(j == prev) continue;
		dfs(j , i , mp) ; 
 
	}
	mp[a[i]]-- ; 
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;

	int n ; 
	cin >> n ; 
	for(int i = 1 ; i <= n ; ++i){
		cin >> a[i] ; 
	}
	for(int i = 0; i < n -1 ; ++i){
		int u , v; 
		cin >> u >> v; 
		gr[u].push_back(v) ; 
		gr[v].push_back(u) ; 
	}
	
	map<int,int> mp ; 
	dfs(1 , -1 , mp) ; 
	sort(ans.begin(), ans.end()) ; 
	for(auto & i : ans){
		cout << i << '\n' ; 
	}
	
}
