#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 111;
const int Max = 2e5 + 10;
int re = 0;
string O[] = {
    "YES",
    "NO",
    "Yes",
    "No",
};
int ON = 0;
vector<int> ans;
int p[Max];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p[i];
  }
  int o = n;
  while (o != 0) {
    ans.push_back(o);
    o = p[o];
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i] << " ";
  }
  return 0;
}
