#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > ad;
vector<int> cam(0);
vector<bool> vis;
bool k = false;
void dfs(const int &m) {
  vis[m] = true;
  if (m == ad.size() - 1) {
    k = true;
  } else
    for (int i = 0; i < ad[m].size(); i++) {
      if (!vis[ad[m][i]]) dfs(ad[m][i]);
      if (k) break;
    }
  if (k) {
    cam.push_back(m);
  }
}
int main() {
  int n;
  cin >> n;
  ad.resize(n + 1, vector<int>(0));
  vis.resize(n + 1, false);
  for (int i = int(2); i < int(n + 1); i += int(1)) {
    int x;
    cin >> x;
    ad[i].push_back(x);
    ad[x].push_back(i);
  }
  dfs(1);
  for (int i = cam.size() - 1; i >= 0; i--) cout << cam[i] << " ";
  return 0;
}
