#include <bits/stdc++.h>
using namespace std;
int n, m, v[300009], a;
vector<int> e;
int main() {
  cin >> n, a = n;
  for (int i = 2; i <= n; i++) cin >> v[i];
  while (a != 1) e.push_back(a), a = v[a];
  e.push_back(1);
  reverse(e.begin(), e.end());
  for (auto i : e) cout << i << ' ';
}
