#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int mas[300500];
  cin >> n;
  int ans[300000];
  for (int i = 0; i < n - 1; i++) {
    cin >> mas[i];
  }
  int st = n - 2;
  ans[0] = n;
  int i = 1;
  while (mas[st] != 1) {
    ans[i] = mas[st];
    i++;
    st = mas[st] - 2;
  }
  ans[i] = 1;
  for (int j = i; j >= 0; j--) cout << ans[j] << " ";
  return 0;
}
