#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 10;
struct tonod {
  int p, next;
} e[M];
int head[M], top = 1, fa[M];
void ins(int x, int y) {
  e[top].p = y, e[top].next = head[x], head[x] = top, top++;
}
void insert(int x, int y) { ins(x, y), ins(y, x); }
void dfs(int u, int f) {
  fa[u] = f;
  for (int i = head[u]; ~i; i = e[i].next) {
    int v = e[i].p;
    if (v != f) dfs(v, u);
  }
}
int ans[M], cnt, a;
int main() {
  memset(head, -1, sizeof(head));
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) scanf("%d", &a), insert(a, i + 1);
  dfs(1, 0);
  while (fa[n]) ans[++cnt] = n, n = fa[n];
  printf("1 ");
  for (int i = cnt; i >= 1; i--) printf("%d ", ans[i]);
  printf("\n");
}
