#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#include <bits/stdc++.h>
#ifdef __LOCAL
	#include <debug/debugger.h>
#endif
#include <ext/pb_ds/assoc_container.hpp>
#define PB push_back
#define PI acos(-1)
#define all(x) x.begin(),x.end()
#define vi vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define vb vector<bool>
#define vull vector<ull>
#define vvi vector<vector<ll> >
#define vvii vector<vii>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read(x) long long x;cin>>x;
#define FOR(a,b,c,d) for(int a=b;a<=c;a+=d)
#define MP make_pair
#define F first
#define AS assign
#define S second
#define debug(x) cout<<(#x)<<": "<<(x)<<"\n"
#define SZ(x) x.size()
#define mod 1000000007
#define lg2(x) 63-(__builtin_ctzll(x))
#define RZ resize
#define IN insert
#define X real()
#define Y imag()
#define INF (((1LL<<62LL)-1LL)*2)-1LL
#define FBO find_by_order
#define OFK order_of_key
#define INPUT(x) freopen(x,"r",stdin)
#define OUTPUT(x) freopen(x,"w",stdout)
#define EPS 1e-9
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
typedef unsigned long long ull;
typedef long double d64;
typedef complex<ll>P;
ll modpow(ll x,ll n,ll m) {if(n==0)return 1%m;long long u = modpow(x,n/2,m);u = (u*u)%m;if(n%2==1)u=(u*x)%m;return u;}

ll n;
vector<vector<ll> >G; 
vi color;
vb mk;
vi coun;

void dfs(int x,int e){
	if(coun[color[x]]==0){
		mk[x]=1;
	}
	coun[color[x]]++;
		for(auto c:G[x]){
			if(c!=e){
				dfs(c,x);
			}
		}
	coun[color[x]]--;
}

int main(){
fast
	
		cin>>n;
			G.AS(n+5,vector<ll>());
			color.RZ(n+5);
			mk.RZ(n+5);
			coun.RZ(100040);

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

			for(ll a,b,i=1;i<=n-1;i++){
				cin>>a>>b;
				G[a].PB(b);
				G[b].PB(a);
			}

			dfs(1,1);

		for(int i=1;i<=n;i++){
			if(mk[i])cout<<i<<"\n";
		}


	return 0;
}
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 100005;

int C[N];
vi g[N];
int cols[N];
vi ans;

void dfs(int c, int p) {
  if(cols[C[c]] == 0) {
    ans.pb(c);
  }
  cols[C[c]]++;
  rep(i,0,g[c].size()) {
    int u = g[c][i];
    if(u != p) {
      dfs(u, c);
    }
  }
  cols[C[c]]--;
}

int main() {
  int n;
  S(n);
  rep(i,1,n+1) {
    S(C[i]);
  }
  rep(i,0,n-1) {
    int u,v;
    S2(u,v);
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1, -1);
  sort(all(ans));
  rep(i,0,ans.size()) {
    P(ans[i]);
  }
  return 0;
}
