//W4P3R
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register ll
#define fr first
#define sd second
#define pa pair<ll,ll>
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define N 200010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
inline ll lowbit(ll x){return x&(-x);}
int n;
vector<int>e[N];
int sz[N],f[N];
void dfs(int x)
{
	sz[x]=1;
	for(int y:e[x]){dfs(y);sz[x]+=sz[y];}
	int sum=0;vector<int>v;
	for(int y:e[x])
	{
		if(sz[y]%2==0){if(f[y]<0)f[x]+=f[y];else sum+=f[y];}
		else {v.pb(f[y]);}
	}
	sort(v.begin(),v.end());
	int op=1;
	for(int val:v){f[x]+=op*val;op=-op;}
	//cout<<"WTF:"<<x<<" "<<sum<<" "<<op<<" "<<f[x]<<" "<<(v.size()?v[0]:0)<<endl;
	f[x]+=op*sum+1;
}
int main()
{
	//ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	FOR(i,2,n)
	{
		int fa=read();
		e[fa].pb(i);
	}
	dfs(1);
	//FOR(i,1,n)cout<<f[i]<<' ';cout<<'\n';
	cout<<(n+f[1])/2<<'\n';
	return 0;
}
//gl


#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = b; i >= a; i--)
 
using namespace std;	

const int N = 200111;

int n, s, t, sub[N], ans[N], e = 1;
vector<int> g[N];

pair<int, int> dfs(int v, int p) {
	pair<int, int> a = {0, v};
	for (auto u : g[v]) {
		if (u != p) {
			auto b = dfs(u, v);
			b.first++;
			a = max(a, b);
		}
	}
	return a;
}

void go(int v, int p) {
	sub[v] = (v == t);
	for (auto u : g[v])
		if (u != p) {
			go(u, v);
			sub[v] |= sub[u];
		}
}

void solve(int v, int p) {
	ans[v] = e;
	sort(g[v].begin(), g[v].end(), [&](int a, int b) {
		return sub[a] < sub[b];
	});
	for (auto u : g[v]) 
		if (u != p) {
			e++;
			solve(u, v);
		}
	e++;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin >> n;
	rep(i, 1, n - 1) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	s = dfs(1, 0).second;
	t = dfs(s, 0).second;
	
	go(s, 0);
	solve(s, 0);
	
	rep(i, 1, n)
		cout << ans[i] << " ";	
	return 0;
}
