#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  stack<int> S;
  vector<int> routers(n - 1);
  for (int i = 0; i < n - 1; ++i) cin >> routers[i];
  int i = n - 2;
  S.push(n);
  while (i >= 0) {
    S.push(routers[i]);
    i = routers[i] - 2;
  }
  while (!S.empty()) {
    if (S.size() > 1) {
      cout << S.top() << " ";
    } else {
      cout << S.top() << endl;
    }
    S.pop();
  }
  return 0;
}
