#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n - 1);
  for (long long i = 0; i < (long long)n - 1; i++) cin >> a[i];
  long long p = n;
  vector<long long> c = {n};
  while (p > 1) {
    p = a[p - 2];
    c.push_back(p);
  }
  for (long long i = 0; i < (long long)c.size(); i++)
    cout << c[c.size() - i - 1] << ' ';
  return 0;
}
