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