#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n;
  vector<int> v(n + 1);
  v[1] = 0;
  for (int i = 2; i <= n; ++i) {
    cin >> x;
    v[i] = (x);
  }
  int i = n;
  vector<int> rev;
  while (i != 0) {
    rev.push_back(i);
    i = v[i];
  }
  for (auto itr = rev.rbegin(); itr != rev.rend(); ++itr) {
    cout << *itr << " ";
  }
}
