#include<bits/stdc++.h>
typedef int LL;
typedef double dl;
#define opt operator
#define pb push_back
#define pii std::pair<LL,LL>
const LL maxn=1e5+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
void Chkmin(LL &x,LL y){
	if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
	if(y>x) x=y;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
	return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
LL n;
LL size[maxn],f[maxn];
std::vector<LL> V[maxn];
void Dfs(LL u){
	size[u]=1;
	for(LL i=0;i<V[u].size();++i){
		LL v(V[u][i]);
		Dfs(v);
		size[u]^=size[v];
	}
	static LL p[maxn];
	LL tot(0);
	LL sum1(0),sum2(0);
	for(LL i=0;i<V[u].size();++i){
		LL v(V[u][i]);
		LL a(f[v]),b(size[v]);
		if(b){
			p[++tot]=a;
		}else if(a<=0){
			sum1+=a;
		}else{
			sum2+=a;
		}
	}
	std::sort(p+1,p+1+tot);
	f[u]=1; f[u]+=sum1;
	for(LL i=1;i<=tot;++i){
		if((i-1)&1){
			f[u]-=p[i];
		}else{
			f[u]+=p[i];
		}
	}
	if(tot&1){
		f[u]-=sum2;
	}else{
		f[u]+=sum2;
	}
}
int main(){
//	freopen("y1.txt","r",stdin);
	n=Read();
	for(LL i=2;i<=n;++i){
		LL x(Read());
		V[x].pb(i);
	}
	Dfs(1);
//	for(int i=1;i<=n;++i){
//  	    printf("%d ",f[i]);
//    }puts("");
	assert(!(n+f[1]&1));
	printf("%d\n",n+f[1]>>1);
	return 0;
}




#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define fo(i,x,y) for(int i = x;i <= y;++i)
#define fd(i,x,y) for(int i = x;i >= y;--i)
using namespace std;
int n,e[200010][2],lst[100010],stk[100010],tot,c[100010],x,y;
bool bz[100010];
char ch[20];
int rd()
{
	int x=0,sig=1;
	char c;
	for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
	for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
	return x*sig;
}
void print(int x,char sp)
{
	int w = -1,sig = 0;
	if(x == 0) w = 0,ch[0] = 48;
	if(x < 0) sig = 1,x = -x;
	while(x > 0) ch[++w] = x % 10 + 48,x /= 10;
	if(sig == 1) putchar('-');
	fd(i,w,0) putchar(ch[i]),ch[i] = 0;putchar(sp);
}
void add(int x,int y)
{
	e[++tot][0] = y,e[tot][1] = lst[x],lst[x] = tot;
}
void dg(int x,int fa)
{
	stk[c[x]]++;
	if(stk[c[x]] <= 1) bz[x] = 1;
	for(int i = lst[x];i;i = e[i][1])
	{
		int v = e[i][0];
		if(v == fa) continue;
		dg(v,x);
	}
	stk[c[x]]--;
}
int main()
{
	//freopen("E.in","r",stdin);
//	freopen("E.out","w",stdout);
	n = rd();
	fo(i,1,n) c[i] = rd();
	fo(i,1,n - 1) x = rd(),y = rd(),add(x,y),add(y,x);
	dg(1,0);
	fo(i,1,n) if(bz[i]) print(i,'\n');
	return 0;
}
