#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<int> ans;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  adj.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    x--;
    adj[i + 1].push_back(x);
  }
  adj[0].push_back(-1);
  int c = n - 1;
  while (c != -1) {
    ans.push_back(c);
    c = adj[c][0];
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] + 1 << " ";
  }
  return 0;
}
