#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;
int n;
int adad[N];
vector<int> path;
void back(int x) {
  if (x == 1) {
    path.push_back(x);
    return;
  }
  path.push_back(x);
  back(adad[x]);
}
void solve() {
  back(n);
  for (int i = path.size() - 1; i >= 0; i--) {
    cout << path[i] << " ";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> adad[i];
  }
  solve();
}
