#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
vector<int> s;
vector<int> ar[200001];
void dfs(int node, int n) {
  s.push_back(node);
  if (node == n) {
    for (int i = 0; i < s.size() - 1; i++) {
      cout << s[i] << " ";
    }
    cout << n;
  }
  for (int child : ar[node]) {
    dfs(child, n);
  }
  s.pop_back();
}
void solve() {
  int n, p;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p;
    ar[p].push_back(i);
  }
  dfs(1, n);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  auto start1 = high_resolution_clock::now();
  solve();
  auto stop1 = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop1 - start1);
}
