#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a;
  vector<int> v;
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    v.push_back(a);
  }
  int tar = n;
  vector<int> ans;
  while (tar != 1) {
    ans.push_back(tar);
    if (tar == 1)
      return 0;
    else
      tar = v[tar - 2];
  }
  ans.push_back(1);
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i] << " ";
  }
  return 0;
}
