#include <bits/stdc++.h>
using namespace std;
int fa[200002];
int n;
vector<int> ans;
void dfs(int pos) {
  ans.push_back(pos);
  if (fa[pos] == pos) return;
  dfs(fa[pos]);
}
int main() {
  cin >> n;
  fa[1] = 1;
  for (int i = 2; i <= n; i++) {
    cin >> fa[i];
  }
  dfs(n);
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i] << " ";
  }
}
