#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 1;
const int MOD = 1e9 + 7;
long long a[MAXN], b[MAXN];
bool used[MAXN];
vector<int> g[MAXN];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  long long n, m, cnt = 0, ans = 0;
  bool y = 0;
  cin >> n;
  a[1] = 1;
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  cnt = n;
  while (cnt != 1) {
    ans++;
    b[ans] = cnt;
    cnt = a[cnt];
  }
  reverse(b + 1, b + ans + 1);
  cout << 1 << " ";
  for (int i = 1; i <= ans; i++) {
    cout << b[i] << " ";
  }
  return 0;
}
