#include <bits/stdc++.h>
using namespace std;
struct node {
  int val;
  int parent;
};
int main() {
  int n;
  cin >> n;
  node nodes[n];
  for (int i = 1; i <= n; i++) {
    nodes[i].val = i;
    nodes[i].parent = i;
  }
  int x;
  for (int i = 2; i <= n; i++) {
    cin >> x;
    nodes[i].parent = x;
  }
  stack<int> s;
  int i = n;
  while (i != 1) {
    s.push(i);
    i = nodes[i].parent;
  }
  cout << "1"
       << " ";
  while (!s.empty()) {
    cout << s.top() << " ";
    s.pop();
  }
  return 0;
}
