#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t r[200001], n, c[200001], t, m;
  cin >> n;
  r[1] = 1;
  for (int i = 2; i <= n; i++) {
    cin >> r[i];
  }
  t = n;
  c[1] = n;
  m = 2;
  while (t != 1) {
    c[m] = r[t];
    t = c[m];
    m++;
  }
  for (int i = m - 1; i > 0; i--) {
    cout << c[i] << " ";
  }
  return 0;
}
