#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a[200001], r[200001], k = 0, d;
  scanf("%d", &n);
  for (i = 2; i <= n; i++) cin >> a[i];
  r[k] = n;
  while (r[k] != 1) {
    d = r[k];
    k++;
    r[k] = a[d];
  }
  for (i = k; i >= 0; i--) printf("%d ", r[i]);
  return 0;
}
