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