#include <bits/stdc++.h>
using namespace std;
void search(int x, int p[]) {
  if (x != 1) search(p[x], p);
  cout << x << " ";
}
int main() {
  int n;
  cin >> n;
  int p[n + 1];
  for (int i = 2; i <= n; i++) cin >> p[i];
  search(n, p);
  return 0;
}
