#include <bits/stdc++.h>
using namespace std;
const long long int mod = (long long int)1e9 + 7;
const long long int inf = 1e18;
int solve() {
  long long int n;
  cin >> n;
  vector<long long int> v(n + 11);
  for (long long int i = 2; i <= n; i++) {
    cin >> v[i];
  }
  vector<long long int> ans;
  while (n > 0) {
    ans.push_back(n);
    n = v[n];
  }
  sort((ans).begin(), (ans).end());
  for (auto it : ans) {
    cout << it << " ";
  }
  cout << "\n";
  return 0;
}
int main() {
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
