EOJ_1063_树的双亲存储法
作者:互联网
#include<bits/stdc++.h>
using namespace std;
vector<int> parents[1000002];
void postOrder(int parent)
{
for(int i=0; i<parents[parent].size() ;i++){
postOrder(parents[parent][i]);
}
cout<< parent <<" ";
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++){
int parentTmp;
cin>>parentTmp;
if(parentTmp!=-1)
parents[parentTmp].push_back(i);
}
postOrder(0);
return 0;
}
标签:std,parent,int,EOJ,1063,双亲,parents,parentTmp,postOrder 来源: https://blog.csdn.net/xyc859666356/article/details/121090959