#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, n, t;
  cin >> n;
  t = n;
  k = n;
  vector<int> routers;
  while (--n) {
    int x;
    cin >> x;
    routers.push_back(x);
  }
  routers.push_back(t);
  vector<int> answer;
  while (1) {
    if (routers[t - 1] <= 1) {
      break;
    }
    answer.push_back(routers[t - 1]);
    t = routers[t - 1] - 1;
  }
  cout << 1;
  for (int i = (answer.size() - 1); i > 0; i--) {
    cout << " " << answer[i];
  }
  cout << " " << k;
  return 0;
}
