#include <bits/stdc++.h>
using namespace std;
void func(vector<int>& mass, int i, vector<int>& out) {
  if (i >= 2) {
    out.push_back(i);
    func(mass, mass[i], out);
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> Mass;
  Mass.push_back(0);
  Mass.push_back(0);
  vector<int> Out;
  Out.push_back(1);
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    Mass.push_back(x);
  }
  func(Mass, n, Out);
  Out.push_back(1);
  for (int i = Out.size() - 1; i > 0; i--) {
    cout << Out[i] << " ";
  }
}
