#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-13;
const long double PI = acos(-1);
const int INF = (int)1e9;
const long long INFF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MXN = (int)1e6 + 7;
int prt[MXN];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 2; i < n + 1; i++) scanf("%d", prt + i);
  int cp = n;
  vector<int> ans;
  while (cp) {
    ans.push_back(cp);
    cp = prt[cp];
  }
  reverse(begin(ans), end(ans));
  for (int i = 0; i < ((int)(ans).size()); i++)
    printf("%d%c", ans[i], " \n"[i == ((int)(ans).size()) - 1]);
  return 0;
}
