#include <bits/stdc++.h>
using namespace std;
vector<long long int> solve(long long int n, vector<long long int> adj[]) {
  vector<long long int> temp;
  stack<long long int> s;
  vector<bool> vis(n + 1, false);
  s.push(n);
  while (!s.empty()) {
    long long int src = s.top();
    s.pop();
    vis[src] = true;
    temp.push_back(src);
    for (auto p : adj[src]) {
      if (!vis[p]) s.push(p);
    }
  }
  return temp;
}
int main() {
  long long int n;
  cin >> n;
  vector<long long int> adj[n + 1];
  for (long long int i = 2; i <= n; i++) {
    long long int temp;
    cin >> temp;
    adj[i].push_back(temp);
  }
  vector<long long int> res = solve(n, adj);
  for (long long int i = res.size() - 1; i >= 0; i--) cout << res[i] << " ";
  cout << "\n";
  return 0;
}
