#include <bits/stdc++.h>
using namespace std;
ifstream f("1.in");
ofstream g("1.out");
int dd[200005];
int n, cnt, x;
void dfs(int node) {
  if (dd[node] != 0) {
    cnt++;
    dfs(dd[node]);
  }
  cout << node << " ";
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> x;
    dd[i] = x;
  }
  dfs(n);
  return 0;
}
