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