#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int fa[N], mx[N], n;   vector<int> son[N];   vector<int> ans;   bool cmp(const int x, const int y) { return mx[x] < mx[y]; }   void dfs(int x) {     int s = son[x].size();     for (int i = 0; i < s; ++i) {       int& sn = son[x][i];       dfs(sn);       mx[x] = max(mx[x], mx[sn] + 1);     }     sort(son[x].begin(), son[x].end(), cmp);   }   void DFS(int x) {     printf( %d  , x);     for (int i = 0; i < son[x].size(); ++i) {       int& sn = son[x][i];       DFS(sn);       if (i == 0) continue;       for (int j = 0; j <= mx[son[x][i - 1]]; ++j) ans.push_back(sn);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       scanf( %d , &fa[i]);       son[fa[i]].push_back(i);     }     dfs(0);     DFS(0);     int s = ans.size();     printf(  n%d n , s);     for (int i = 0; i < s; ++i) printf( %d  , ans[i]);     return 0;   }   