#include <bits/stdc++.h>
using namespace std;
int n;
int p[200000];
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> p[i];
    p[i]--;
  }
  stack<int> res;
  int cur = n - 1;
  while (cur != 0) {
    res.push(cur);
    cur = p[cur];
  }
  res.push(0);
  while (!res.empty()) {
    cout << res.top() + 1 << " ";
    res.pop();
  }
  cout << "\n";
}
