#include <bits/stdc++.h>
using namespace std;
int pre[200001], tot, ans[200001], a, n;
int main() {
  cin >> n;
  pre[1] = -1;
  for (int i = 2; i <= n; i++) {
    cin >> a;
    pre[i] = a;
  }
  int i = n;
  while (pre[i] != -1) {
    tot++;
    ans[tot] = pre[i];
    i = pre[i];
  }
  cout << 1 << " ";
  for (int i = tot - 1; i >= 1; i--) cout << ans[i] << " ";
  cout << n;
}
