#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5, mod = (long long int)1e9 + 7;
set<long long int> st;
long long int cnt[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int arr[n - 1];
  for (long long int i = 0; i < n - 1; i++) {
    cin >> arr[i];
  }
  long long int p = arr[n - 2];
  vector<long long int> v;
  v.push_back(n);
  v.push_back(p);
  while (p != 1) {
    v.push_back(arr[p - 2]);
    p = arr[p - 2];
  }
  for (auto it = v.rbegin(); it != v.rend(); it++) cout << *it << " ";
  return 0;
}
