#include <bits/stdc++.h>
using namespace std;
int main() {
  stack<int> ans;
  int con[200005];
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) cin >> con[i];
  int now = n;
  ans.push(now);
  while (now != 1) {
    now = con[now];
    ans.push(now);
  }
  while (!ans.empty()) {
    cout << ans.top() << " ";
    ans.pop();
  }
}
