#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
vector<vector<int>> tree;
vector<int> s, m, p;
int dfs(int cur, int par){
p[cur] = par;
s[cur] = 1;
for(auto next : tree[cur]){
if(next == par) continue;
int t = dfs(next, cur);
s[cur] += t;
m[cur] = max(m[cur], t);
}
return s[cur];
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
tree = vector<vector<int>>(N);
s = vector<int>(N);
m = vector<int>(N);
p = vector<int>(N);
FORE(i,1,N-1){
int p; cin >> p;
tree[i].push_back(p);
tree[p].push_back(i);
}
dfs(0,-1);
//join(cerr, ALL(s));
//join(cerr, ALL(m));
//join(cerr, ALL(p));
REP(i,N){
int ans = m[i];
if(p[i] != -1) ans = max(ans, N-s[i]);
cout << ans << endl;
}
return 0;
}