#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; int child = 0;
while (par != root || child != (int)g[root].size())
{
if (child == (int)g[par].size())
{
cout << par << " ";
child = p[par];
int l = 0; int r = (int)g[child].size();
while (l != r-1)
{
int m = (l + r) >> 1;
if (g[child][m] <= par) l = m; else r = m;
}
par = l + 1;
swap(child,par);
continue;
}
par = g[par][child];
child = 0;
}
cout << root << endl;
}
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());
go();
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgogCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgZm9ybihpLG4pIGZvciAoaW50IGk9MDtpPChpbnQpbjtpKyspCiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG47IGludCByb290ID0gMDsKdmVjdG9yIDxpbnQ+IGdbMTAwNTAwXTsKaW50IHBbMTAwNTAwXTsKIAp2b2lkIGdvKCkKewogICAgICAgIGludCBwYXIgPSByb290OyBpbnQgY2hpbGQgPSAwOwogICAgICAgIAogICAgICAgIHdoaWxlIChwYXIgIT0gcm9vdCB8fCBjaGlsZCAhPSAoaW50KWdbcm9vdF0uc2l6ZSgpKQogICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChjaGlsZCA9PSAoaW50KWdbcGFyXS5zaXplKCkpIAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IHBhciA8PCAiICI7CiAgICAgICAgICAgICAgICAgICAgICAgIGNoaWxkID0gcFtwYXJdOwogICAgICAgICAgICAgICAgICAgICAgICBpbnQgbCA9IDA7IGludCByID0gKGludClnW2NoaWxkXS5zaXplKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChsICE9IHItMSkKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCBtID0gKGwgKyByKSA+PiAxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChnW2NoaWxkXVttXSA8PSBwYXIpIGwgPSBtOyBlbHNlIHIgPSBtOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIHBhciA9IGwgKyAxOwogICAgICAgICAgICAgICAgICAgICAgICBzd2FwKGNoaWxkLHBhcik7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcGFyID0gZ1twYXJdW2NoaWxkXTsKICAgICAgICAgICAgICAgIGNoaWxkID0gMDsKICAgICAgICB9CiAgICAgICAgY291dCA8PCByb290IDw8IGVuZGw7Cn0KIAppbnQgbWFpbigpIHsKICBjaW4gPj4gbjsKICBmb3JuKGksbi0xKQogIHsKICAgICAgICBpbnQgcGFyOyBzY2FuZigiJWQiLCZwYXIpOwogICAgICAgIHBbaSsxXSA9IHBhcjsKICAgICAgICBnW3Bhcl0ucGIoaSsxKTsKICB9CiAgZm9ybihpLG4pCiAgICAgICAgICBzb3J0KGdbaV0uYmVnaW4oKSxnW2ldLmVuZCgpKTsKIAogIGdvKCk7CiAgCiAgcmV0dXJuIDA7Cn0=