#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int MOD = 1e9 + 7;
const long long inf = 2e18;
int n, m;
int a[maxn];
vector<int> v;
void solve() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    --a[i];
  }
  v.push_back(n - 1);
  int x = n - 1;
  while (x != 0) {
    x = a[x];
    v.push_back(x);
  }
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << " ";
    cout << v[i] + 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int test = 1;
  while (test--) {
    solve();
    cout << '\n';
  }
  return 0;
}
