水题一道
CF 1056D
算出每个子树的大小即可
void solve(){
int n;
cin>>n;
vector<int>num(n+1);
vector<vector<int>>E(n+1);
for(int i=2;i<=n;++i){
int p;
cin>>p;
E[p].push_back(i);
}
function<void(int,int)>dfs=[&](int x,int f){
if(E[x].size()==0){
num[x]=1;
return;
}
for(int v:E[x]){
dfs(v,x);
num[x]+=num[v];
}
};
dfs(1,0);
sort(num.begin()+1,num.end());
for(int i=1;i<=n;++i){
cout<<num[i]<<" \n"[i==n];
}
return;
}