#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
int32_t main() {
  long long n;
  cin >> n;
  long long a[n + 1], b[n + 1], k = 0;
  a[1] = 1;
  for (long long i = 2; i <= n; i++) cin >> a[i];
  for (long long i = n; i > 1;) {
    b[k++] = i;
    i = a[i];
  }
  cout << "1 ";
  for (long long i = k - 1; i >= 0; i--) cout << b[i] << " ";
  return 0;
}
