#include <bits/stdc++.h>
using namespace std;
void solve() {
  int i, n, temp;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b;
  a[0] = 0;
  a[1] = 0;
  for (i = 2; i <= n; i++) {
    cin >> a[i];
  }
  i = n;
  while (1) {
    b.push_back(i);
    i = a[i];
    if (i < 1) {
      break;
    }
  }
  for (i = b.size() - 1; i >= 0; i--) {
    cout << b[i] << " ";
  }
}
int main() {
  solve();
  return 0;
}
