#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &dig) {
  dig = 0;
  bool flag = false;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') flag = true, c = getchar();
  while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
  if (flag) dig = -dig;
}
const int MAXN = (int)2e5 + 5;
struct Tree {
  int father;
  int id;
};
Tree tree[MAXN];
int n, top = 0, a;
int stack1[MAXN];
inline void init() { read(n); }
inline void solve() {
  tree[1].father = -1;
  for (register int i = (2); i <= (n); ++i) {
    read(a);
    tree[i].id = i;
    tree[i].father = a;
  }
  int curr = n;
  while (tree[curr].father != -1) {
    stack1[++top] = tree[curr].id;
    curr = tree[curr].father;
  }
  printf("1 ");
  for (register int i = (top); i >= (1); --i) printf("%d ", stack1[i]);
}
int main() {
  init();
  solve();
  return 0;
}
