#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  unordered_map<int, int> graph;
  for (int i = 0; i < n - 1; i++) cin >> graph[i + 2];
  stack<int> ans;
  while (1) {
    ans.push(n);
    if (n == 1) break;
    n = graph[n];
  }
  while (!ans.empty()) {
    cout << ans.top() << " ";
    ans.pop();
  }
  cout << endl;
  return 0;
}
