#include <bits/stdc++.h>
using namespace std;
const long int N = 200000;
vector<int> parent(N);
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int m;
    cin >> m;
    parent[i + 2] = m;
  }
  int temp = n;
  vector<int> store;
  while (temp != 1) {
    store.push_back(parent[temp]);
    int a = parent[temp];
    temp = a;
  }
  reverse(store.begin(), store.end());
  for (int i : store) {
    cout << i << " ";
  }
  cout << n;
}
int main() {
  solve();
  return 0;
}
