#include <iostream>
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer
//#define mp make_pair
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define pb push_back
 #define INF 1e18
#define min(a,b) (a<b?a:b)
#define forn(n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define MAX 1e18;
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define vmin *min_element
#define vmax *max_element
#define pii pair<int,int>
int mod = 1e9+7;
#define N 100005
#define pi 3.141592653589793238
 
 
using namespace std;

vector<int>adj[N];
vector<int>vis(N,0);
vector<int>color(N,0);
vector<int>good(N,0);

map<int,int>mp;
void dfs(int s,int par)
{
	vis[s]=1;
	mp[color[s]]++;
	for(int i=0; i<adj[s].size();i++)
	{
		if(adj[s][i]!=par)
		{
		dfs(adj[s][i],s);	
		}
	}
	
	if(mp[color[s]]==1)
	{
		good[s] = 1;
		mp[color[s]]--;
	}
	else
	{
		mp[color[s]]--;
	}
	
 }


void solve(int cc)
{
	int n;
	cin>>n;
	for(int i=1; i<=n;i++)
	{
		cin>>color[i];
	}
int p =n-1;
while(p--)
{
	int a,b;
	cin>>a>>b;
	adj[a].pb(b);
	adj[b].pb(a);
}
dfs(1,0);
for(int i=1; i<=n; i++)
if(good[i]==1)
cout<<i<<endl;

}
signed  main()
{
IOS;

int t = 1;
//cin>>t;
 int cc =0;
 while(t--)
 {
 //	cout<<f(0,0,4,);
 	cc++;
solve(cc);
cout<<endl;
 
 }
}
//110101
//((()))
//(())()
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<ll>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
// void warshall_floyd(ll n)
// {
//     for (size_t i = 0; i < n; i++)
//     {
//         for (size_t j = 0; j < n; j++)
//         {
//             for (size_t k = 0; k < n; k++)
//             {
//                 dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
//             }
//         }
//     }
// }

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}
struct Matrix
{
    int sz;
    ll x[33][33];
};

Matrix multiply(Matrix A, Matrix B)
{
    Matrix C;
    C.sz = A.sz;
    for (int i = 0; i < C.sz; i++)
    {
        for (int j = 0; j < C.sz; j++)
        {
            C.x[i][j] = 0;
        }
    }

    for (int i = 0; i < A.sz; i++)
    {
        for (int j = 0; j < A.sz; j++)
        {
            for (int k = 0; k < A.sz; k++)
            {
                C.x[i][k] += A.x[i][j] * B.x[j][k];
                C.x[i][k] %= MOD;
            }
        }
    }

    return C;
}

Matrix powers(Matrix A, ll T)
{
    Matrix E[64], F;
    E[0] = A;
    for (int i = 1; i < 62; i++)
    {
        E[i] = multiply(E[i - 1], E[i - 1]);
    }

    F.sz = E[0].sz;

    for (int i = 0; i < F.sz; i++)
    {
        for (int j = 0; j < F.sz; j++)
        {
            if (i == j)
                F.x[i][j] = 1;
            else
                F.x[i][j] = 0;
        }
    }

    for (int i = 62; i >= 0; i--)
    {
        if ((T & (1LL << i)) != 0LL)
        {
            F = multiply(F, E[i]);
        }
    }
    return F;
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

vector<ll> ans;
vector<bool> seen;
vector<long long> C;

void dfs(Graph &G, int v, map<ll, ll> &color)
{
    seen[v] = true;
    if (color[C[v]] == 0)
    {
        ans.push_back(v);
    }
    color[C[v]]++;
    for (auto nv : G[v])
    {
        if (seen[nv])
            continue;

        dfs(G, nv, color);
    }
    color[C[v]]--;
}

int main()
{

    long long N;
    scanf("%lld", &N);
    C.assign(N, 0);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &C[i]);
    }
    Graph G(N);
    seen.assign(N, false);
    for (int i = 0; i < N - 1; i++)
    {
        ll a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    map<ll, ll> color;
    dfs(G, 0, color);

    SORT(ans);
    for (auto &&i : ans)
    {
        cout << i + 1 << endl;
    }

    return 0;
}
