#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100 * 1000;
int p[N], n;
vector<int> ans;
inline void read_input() {
  cin >> n;
  for (int i = 2; i <= n; i++) cin >> p[i];
}
inline void solve() {
  int x = n;
  while (x > 1) {
    ans.push_back(x);
    x = p[x];
  }
  ans.push_back(1);
}
inline void write_output() {
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  read_input(), solve(), write_output();
  return 0;
}
