#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int N = 120000;
vector<int> E[N];
map<vector<int>, int> id;
int ans[N], p[N], vis[N];
int n, cnt;
int work(int x) {
vector<int> u;
for(int i = 0; i < E[x].size(); i++) {
int y = E[x][i];
u.push_back(work(y));
}
sort(u.begin(), u.end());
if (!id[u]) id[u] = ++cnt;
ans[x] = id[u];
return ans[x];
}
int main(){
scanf("%d", &n);
for(int i = 2; i <= n; i++){
scanf("%d", &p[i]);
E[p[i]].push_back(i);
}
work(1);
cnt = 0;
for(int i = 1; i <= n; i++) {
if (!vis[ans[i]]) {
vis[ans[i]] = ++cnt;
}
ans[i] = vis[ans[i]];
}
for(int i = 1; i <= n; i++) printf("%d ", ans[i]);
puts("");
}