#include<iostream>
#include<vector>
using namespace std;
vector<int> sons[100001];//存每个节点的子节点列
int ctr = 0;
void vis(int a){
for(int i = 0; i < sons[a].size(); i++){
vis(sons[a][i]);
}
if(ctr++){
cout << " ";
}
cout << a;
}
int main(){
int N;
cin >> N;
for(int i = 0; i < N; i++){
int temp;
cin >> temp;
if(temp != -1){
sons[temp].insert(sons[temp].end(), i);
}
}
vis(0);
return 0;
}
这题根结点是 0 啊?