#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int p[maxn];
vector<int> pa;
int main() {
  int n, f;
  scanf("%d", &n);
  p[1] = 1;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &f);
    p[i] = f;
  }
  int r = n;
  while (p[r] != r) {
    pa.push_back(r);
    r = p[r];
  }
  reverse(pa.begin(), pa.end());
  printf("1");
  for (int i = 0; i < (int)pa.size(); i++) printf(" %d", pa[i]);
  return 0;
}
