#include <bits/stdc++.h>
using namespace std;
int64_t n, k, m;
vector<int> v[200005];
vector<int> ans;
int dfs(int x) {
  int u = 0;
  for (auto i : v[x])
    if (dfs(i) == 1) u = 1;
  if (x == n) u = 1;
  if (u == 1) ans.push_back(x);
  return u;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> k;
    v[k].push_back(i);
  }
  dfs(1);
  reverse(ans.begin(), ans.end());
  for (auto i : ans) cout << i << " ";
  cout << endl;
  return 0;
}
