#include <bits/stdc++.h>
using namespace std;
int D[200001];
int main() {
  int N, i, j, K;
  cin >> N;
  for (i = 2; i <= N; i++) {
    cin >> D[i];
  }
  i = j = N;
  while (D[i] > 1) {
    i = D[i];
    D[--j] = D[i];
  }
  for (; j <= N; j++) cout << D[j] << ' ';
  cout << N;
}
