#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vector<vector<int>> rou(n + 1);
  vector<int> dist(n + 1, -1);
  vector<int> rep(n + 1, -1);
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    rou[a].push_back(i + 1);
  }
  int ori = 1;
  dist[ori] = 0;
  queue<int> cola;
  cola.push(ori);
  while (!cola.empty()) {
    int nodo = cola.front();
    cola.pop();
    for (int i = 0; i < rou[nodo].size(); i++) {
      int ady = rou[nodo][i];
      if (dist[ady] == -1) {
        dist[ady] = dist[nodo] + 1;
        rep[ady] = nodo;
        cola.push(ady);
      }
    }
  }
  int fin = n;
  stack<int> pila;
  pila.push(fin);
  while (rep[fin] != -1) {
    pila.push(rep[fin]);
    fin = rep[fin];
  }
  while (!pila.empty()) {
    cout << pila.top() << " ";
    pila.pop();
  }
  return 0;
}
