#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long p[n + 1];
  p[1] = -1;
  for (long long i = 2; i <= n; i++) cin >> p[i];
  vector<long long> ans;
  long long x = n;
  while (p[x] != -1) {
    ans.push_back(p[x]);
    x = p[x];
  }
  reverse(ans.begin(), ans.end());
  for (long long i : ans) cout << i << " ";
  cout << n << endl;
}
