#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int i = 2, x, n;
  vector<pair<int, int> > p;
  cin >> n;
  for (i = 2; i <= n; i++) {
    cin >> x;
    p.push_back(make_pair(x, i));
  }
  reverse(p.begin(), p.end());
  v.push_back(p[0].second);
  x = p[0].first;
  for (i = 1; i < n; i++) {
    if (p[i].second == x) {
      v.push_back(p[i].second);
      x = p[i].first;
    }
  }
  cout << 1;
  reverse(v.begin(), v.end());
  for (i = 0; i < v.size(); i++) cout << " " << v[i];
  cout << endl;
  return 0;
}
