#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);

int n;
priority_queue<int, vector<int>, greater<int>> good;
vector<int> c(100005);
vector<queue<int>> edge(100005);
vector<int> s(100005, 0);

void dfs(int prev, int now) {
  if(s[c[now]] == 0) {
    good.push(now);
  }
  s[c[now]]++;

  while(!edge[now].empty()) {
    int tmp = edge[now].front();
    edge[now].pop();
    if(tmp != prev) {
      dfs(now, tmp);
    }
  }
  s[c[now]]--;
}

int main() {
  cin >> n;
  rep(i, n) cin >> c[i];

  rep(i, n-1) {
    int a, b; cin >> a >> b;
    a--; b--;
    edge[a].push(b);
    edge[b].push(a);
  }

  dfs(-1, 0);

  while(!good.empty()) {
    cout << good.top()+1 << endl;
    good.pop();
  }

  return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}

//
// Created by mihai145 on 23.02.2021.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int NMAX = 1e5;

int N, w[NMAX + 5];
vector<int> g[NMAX + 5];

int dfs(int node, int parent = -1) {
    int ans = 1;

    w[node] = 1;

    vector<int> v;
    int evenLeft = 0;

    for (auto it : g[node]) {
        if (it != parent) {
            int nextRes = dfs(it, node);
            w[node] += w[it];

            if (w[it] % 2 == 0) {
                if (nextRes <= 0) {
                    ans += nextRes;
                } else {
                    evenLeft += nextRes;
                }
            } else {
                v.push_back(nextRes);
            }
        }
    }

    sort(v.begin(), v.end());
    v.push_back(evenLeft);

    for (int i = 0; i < (int) v.size(); i++)
        if (i % 2 == 0) {
            ans += v[i];
        } else {
            ans -= v[i];
        }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    for (int i = 2; i <= N; i++) {
        int parent;
        cin >> parent;
        g[parent].push_back(i);
    }

    cout << (N + dfs(1)) / 2 << '\n';

    return 0;
}