#include <bits/stdc++.h>
using namespace std;
const int MXN = (int)1e6 + 7;
int prt[MXN];
int main() {
  int n;
  cin >> n;
  for (int i = 2; i < n + 1; i++) {
    cin >> prt[i];
  }
  int cp = n;
  vector<int> ans;
  while (cp) {
    ans.push_back(cp);
    cp = prt[cp];
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
}
