#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n + 1];
  a[1] = -1;
  for (long long int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  vector<long long int> out;
  long long int i = n;
  while (i != -1) {
    out.push_back(i);
    i = a[i];
  }
  reverse(out.begin(), out.end());
  for (long long int i = 0; i < out.size(); i++) {
    cout << out[i] << " ";
  }
  return 0;
}
