#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, j, arr[200005], i, position[200005];
  cin >> n;
  for (i = 2; i <= n; i++) cin >> arr[i];
  if (n == 2)
    cout << "1 2" << endl;
  else {
    position[0] = n;
    position[1] = arr[n];
    if (position[1] == 1) {
      cout << 1 << " " << n << endl;
      return 0;
    } else {
      for (j = 2;; j++) {
        position[j] = arr[position[j - 1]];
        if (position[j] == 1) break;
      }
      for (i = j; i >= 0; i--) cout << position[i] << " ";
      cout << endl;
    }
  }
  return 0;
}
