#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int n;
void rec(int i) {
  if (i > 1) {
    rec(v[i - 1]);
    cout << i << " ";
  } else {
    cout << 1 << " ";
  }
}
int main() {
  cin >> n;
  v = vector<int>(n);
  for (int i = 1; i < n; i++) {
    cin >> v[i];
  }
  rec(v[n - 1]);
  cout << n << "\n";
  return 0;
}
