#include <bits/stdc++.h>
using namespace std;
int N, F[200010], i;
stack<int> S;
int main() {
  cin >> N;
  F[1] = 0;
  for (i = 2; i <= N; ++i) cin >> F[i];
  while (N) S.push(N), N = F[N];
  while (!S.empty()) printf("%d ", S.top()), S.pop();
}
