#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define pb push_back
#define forn(i,n) for (int i=0;i<(int)n;i++)
using namespace std;
int n; int root = 0;
vector <int> g[100500];
int p[100500];
void go()
{
int par = root;
while (par != root || !g[par].empty())
{
if (g[par].empty())
{
cout << par << " ";
par = p[par];
g[par].pop_back();
continue;
}
par = *g[par].rbegin();
}
cout << root << endl;
}
bool cmp(int a,int b) { return a > b; }
int main() {
cin >> n;
forn(i,n-1)
{
int par; scanf("%d",&par);
p[i+1] = par;
g[par].pb(i+1);
}
forn(i,n) sort(g[i].begin(),g[i].end(),cmp);
go();
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgoKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBmb3JuKGksbikgZm9yIChpbnQgaT0wO2k8KGludCluO2krKykKIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbjsgaW50IHJvb3QgPSAwOwp2ZWN0b3IgPGludD4gZ1sxMDA1MDBdOwppbnQgcFsxMDA1MDBdOwoKdm9pZCBnbygpCnsKCWludCBwYXIgPSByb290OwoJCgl3aGlsZSAocGFyICE9IHJvb3QgfHwgIWdbcGFyXS5lbXB0eSgpKQoJewoJCWlmIChnW3Bhcl0uZW1wdHkoKSkgCgkJewoJCQljb3V0IDw8IHBhciA8PCAiICI7CgkJCXBhciA9IHBbcGFyXTsKICAgICAgICAgICAgICAgICAgICAgICAgZ1twYXJdLnBvcF9iYWNrKCk7CgkJCWNvbnRpbnVlOwoJCX0KCQlwYXIgPSAqZ1twYXJdLnJiZWdpbigpOwoJfQoJY291dCA8PCByb290IDw8IGVuZGw7Cn0KCmJvb2wgY21wKGludCBhLGludCBiKSB7IHJldHVybiBhID4gYjsgfQoKaW50IG1haW4oKSB7CiAgY2luID4+IG47CiAgZm9ybihpLG4tMSkKICB7CglpbnQgcGFyOyBzY2FuZigiJWQiLCZwYXIpOwoJcFtpKzFdID0gcGFyOwoJZ1twYXJdLnBiKGkrMSk7CiAgfQogIGZvcm4oaSxuKSBzb3J0KGdbaV0uYmVnaW4oKSxnW2ldLmVuZCgpLGNtcCk7CgogIGdvKCk7CiAgCiAgcmV0dXJuIDA7Cn0=