#include <bits/stdc++.h>
using namespace std;
const int md = 1000000007;
void sol() {
  long long n;
  cin >> n;
  long long a[n - 1];
  for (long long i = 0; i < n - 1; i++) cin >> a[i];
  long long x = n - 2;
  stack<long long> second;
  second.push(n);
  while (x >= 0) {
    second.push(a[x]);
    x = a[x] - 2;
  }
  while (!second.empty()) {
    long long p = second.top();
    second.pop();
    cout << p << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    sol();
  }
  return 0;
}
