#include <bits/stdc++.h>   using namespace std;   const int maxsize = 100005;   const int inf = 1061109567;   vector<int> edge[maxsize];   vector<pair<int, int> > base[maxsize];   int nnext[maxsize];   int n;   int deepth[maxsize];   int siz[maxsize];   int last = 0;   int ans[10 * maxsize];   int cnt = 0;   void dfs1(int u) {     if (edge[u].size() == 0) {       deepth[u] = 1;       return;     }     int maxi = 0;     for (auto v : edge[u]) {       siz[v] = siz[u] + 1;       dfs1(v);       maxi = max(deepth[v], maxi);       base[u].push_back({deepth[v], v});     }     deepth[u] = maxi + 1;     sort(base[u].begin(), base[u].end());     return;   }   void dfs2(int u) {     for (auto v : base[u]) {       nnext[last] = v.second;       last = v.second;       printf( %d  , v.second);       dfs2(v.second);     }     return;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u;       scanf( %d , &u);       edge[u].push_back(i + 1);     }     dfs1(0);     printf( 0  );     dfs2(0);     puts(  );     int gg = 0;     while (nnext[gg]) {       int r = siz[gg] - siz[nnext[gg]] + 1;       for (int i = 0; i < r; i++) ans[cnt++] = nnext[gg];       gg = nnext[gg];     }     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) printf( %d  , ans[i]);     puts(  );     return 0;   }   