#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n + 2];
  vector<int> s;
  s.push_back(n);
  for (int i = 2; i < n + 1; i++) cin >> arr[i];
  arr[1] = 0;
  int k = n;
  while (k > 0) {
    s.push_back(arr[k]);
    k = arr[k];
  }
  for (int i = s.size() - 2; i > -1; i--) {
    cout << s[i] << " ";
  }
  return 0;
}
