#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int p[n - 1];
  for (int x = 0; x < n - 1; x++) {
    cin >> p[x];
  }
  int ansarr[200000];
  int yyy = 0;
  int xxx = n - 2;
  for (int x = 0; x < 1000000000; x++) {
    ansarr[x] = p[xxx];
    if (p[xxx] == 1) {
      yyy = x;
      break;
    }
    xxx = p[xxx] - 2;
  }
  for (int x = yyy; x >= 0; x--) {
    cout << ansarr[x] << " ";
  }
  cout << n;
}
