#include <bits/stdc++.h>   struct edge {     int to, nxt;   } e[100005], e2[100005];   int h[100005], n, cnt, hei[100005], gson[100005], node[100005], N, fa[100005];   void ins(int x, int y) {     e[++cnt].nxt = h[x];     e[cnt].to = y;     h[x] = cnt;   }   void dfs1(int x) {     hei[x] = 1;     for (int i = h[x]; i; i = e[i].nxt) {       dfs1(e[i].to);       hei[x] = std::max(hei[x], hei[e[i].to] + 1);       if (hei[gson[x]] < hei[e[i].to]) gson[x] = e[i].to;     }   }   void dfs2(int x) {     node[++N] = x;     for (int i = h[x]; i; i = e[i].nxt)       if (e[i].to != gson[x]) dfs2(e[i].to);     if (gson[x]) dfs2(gson[x]);   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) scanf( %d , &fa[i]), ins((++fa[i]), i);     dfs1(1);     dfs2(1);     for (int i = 1; i <= n; i++) printf( %d  , node[i] - 1);     printf(  n%d n , n - hei[1]);     for (int i = 1, j = 1, k = 0; i <= n - hei[1]; i++) {       while (j <= n && fa[node[j]] == k) k = node[j++];       if (j > n) break;       printf( %d  , node[j] - 1);       k = fa[k];     }   }   