#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n + 1];
    a[1] = 0;
    for (int i = 2; i <= n; i++) cin >> a[i];
    vector<int> v;
    v.push_back(n);
    n = a[n];
    v.push_back(n);
    while (n != 1) {
      v.push_back(a[n]);
      n = a[n];
    }
    reverse(v.begin(), v.end());
    for (auto x : v) cout << x << " ";
  }
  return 0;
}
