#include <bits/stdc++.h>
using namespace std;
int p[200000 + 100], n, ans[200000 + 100];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 2; i <= n; i++) cin >> p[i];
  int idx = 1, i = p[n];
  ans[0] = n;
  while (1) {
    ans[idx++] = i;
    if (i == 1) break;
    i = p[i];
  }
  for (int i = idx - 1; i >= 0; i--) cout << ans[i] << " ";
}
