#include <bits/stdc++.h>
const long long maxn = 2 * 100001;
using namespace std;
vector<long long> edge[maxn];
bool vis[maxn];
void dfs(long long x, set<long long> &ans, long long n, bool &flag) {
  vis[x] = true;
  if (x == n) {
    flag = 1;
    ans.insert(x);
    return;
  }
  for (auto &i : edge[x]) {
    if (!vis[i]) {
      dfs(i, ans, n, flag);
      if (flag) {
        ans.insert(x);
        return;
      }
    }
  }
}
void solve() {
  long long n, x;
  memset(vis, false, sizeof(vis));
  cin >> n;
  for (long long i = 2; i <= n; i++) {
    cin >> x;
    edge[x].push_back(i);
  }
  set<long long> ans;
  bool flag = false;
  dfs(1, ans, n, flag);
  for (auto &x : ans) {
    cout << x << " ";
  }
  cout << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
