#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 2e5 + 10;
vector<int> adj[maxn];
vector<int> parent(maxn, -1);
void dfs(int u) {
  for (int v : adj[u]) {
    if (parent[v] == -1) {
      parent[v] = u;
      dfs(v);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    adj[x].push_back(i);
  }
  parent[1] = 0;
  dfs(1);
  int cur = n;
  vector<int> path;
  while (cur) {
    path.push_back(cur);
    cur = parent[cur];
  }
  reverse(path.begin(), path.end());
  for (int u : path) cout << u << " ";
  cout << endl;
  return 0;
}
