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