#include <iostream>
#include <algorithm>

using namespace std;

const int kMaxN = 1e5 + 1;

struct E {
  int y, n;
} e[2 * kMaxN];

struct V {
  int c, et;
} a[kMaxN];

int n, p, v[kMaxN];
bool s[kMaxN];

void A(int i, int x, int y) {
  e[i] = {y, a[x].et};
  a[x].et = i;
}

void D(int x, int f) {
  s[x] = !v[a[x].c]++;
  for (int i = a[x].et; i; i = e[i].n) {
    if (e[i].y != f) {
      D(e[i].y, x);
    }
  }
  --v[a[x].c];
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].c;
  }
  for (int i = 1, x, y; i < n; ++i) {
    cin >> x >> y;
    A(i, x, y), A(i + n, y, x);
  }
  D(1, 0);
  for (int i = 1; i <= n; ++i) {
    if (s[i]) {
      cout << i << endl;
    }
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define endl '\n' 
#define ce(ele) cout<<ele<<' '
#define CASE(t) int t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vi vector<ll>
#define cs(ele) cout<<ele<<'\n'
const ll Mod=1e9 +7;const ll M1=998244353;
ll mod(ll n){return ((n%Mod)+Mod)%Mod;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=mod(res*x);x=mod(x*x);y=mod(y>>1);}return mod(res);}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
       
       int n,x;cin>>n>>x;
       vector<int> v;
       f(i,0,n){
           int a;cin>>a;
           if(a!=x)v.pb(a);
       }
       for(auto a:v)ce(a);cout<<endl;
    
}