#include <bits/stdc++.h>
using namespace std;
int main() {
  int test_case;
  test_case = 1;
  while (test_case--) {
    long long int n;
    cin >> n;
    vector<int> a;
    a.push_back(0);
    for (long long int i = 0; i < n - 1; i++) {
      long long int t;
      cin >> t;
      a.push_back(t);
    }
    long long int k = n - 1;
    stack<long long int> s;
    vector<long long int> v;
    s.push(n);
    while (k != 0) {
      s.push(a[k]);
      k = a[k] - 1;
    }
    while (!s.empty()) {
      cout << s.top() << " ";
      s.pop();
    }
  }
  return 0;
}
