#include <bits/stdc++.h>
using namespace std;
template <typename XTYPE>
inline void _var_(const XTYPE& a) {}
template <typename XTYPE>
inline void _vector_(const XTYPE& a) {}
template <typename XTYPE>
inline void _matrix_(const XTYPE& a) {}
inline void fast_input() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
}
const long long LINF = LLONG_MAX;
const int INF = 1000000000;
const double PI = atan(1.0) * 4;
const int MOD = 1e9 + 7;
int n;
vector<int> p;
int main() {
  cin >> n;
  p.resize(n + 1);
  for (int i = 0; i < int(n - 1); i++) {
    int buf;
    cin >> buf;
    buf--;
    p[i + 1] = buf;
  }
  vector<int> ans;
  ans.reserve(n);
  int cur = n - 1;
  ans.push_back(cur);
  while (p[cur] != 0) {
    ans.push_back(p[cur]);
    cur = p[cur];
  }
  ans.push_back(0);
  reverse(ans.begin(), ans.end());
  for (auto t : ans) {
    cout << t + 1 << " ";
  }
  return 0;
}
