#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> padre(n + 1);
  for (int i = 0; i < int(n - 1); i++) {
    cin >> padre[i + 2];
  }
  vector<int> camino;
  int toy = n;
  while (toy != 1) {
    camino.push_back(toy);
    toy = padre[toy];
  }
  camino.push_back(1);
  for (int i = 0; i < int(camino.size()); i++) {
    cout << camino[camino.size() - 1 - i] << " \n"[i == (int)camino.size() - 1];
  }
}
