#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int prev[n - 1];
  vector<int> v;
  for (int i = 0; i < n - 1; ++i) {
    int k;
    cin >> k;
    prev[i] = k;
  }
  int cur = n;
  while (cur != 1) {
    v.push_back(cur);
    cur = prev[cur - 2];
  }
  cout << 1 << ' ';
  for (int i = 0; i < v.size(); ++i) {
    cout << v[v.size() - 1 - i] << ' ';
  }
}
