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