#include <bits/stdc++.h>
using namespace std;
bool isPrime(const int& num) {
  for (int i = 2; i <= ceil(sqrt(num)); i++)
    if (num % i == 0) return false;
  return true;
}
vector<vector<int>> tree;
vector<bool> visited;
int ans = 0;
int aux = 0;
int main() {
  int n;
  cin >> n;
  vector<int> tree(n + 1);
  vector<int> ans;
  tree[1] = -1;
  for (int i = 2; i <= n; i++) {
    cin >> tree[i];
  }
  int k = n;
  while (k != -1) {
    ans.push_back(k);
    k = tree[k];
  }
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
  cout << '\n';
  return 0;
}
