#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[200010], b[200010], t;
  cin >> n;
  for (int i = 2; i <= n; i++) cin >> a[i];
  b[0] = n;
  for (int i = 1;; i++) {
    b[i] = a[b[i - 1]];
    if (b[i] == 1) {
      t = i;
      break;
    }
  }
  for (int i = t; i >= 0; i--) cout << b[i] << ' ';
}
