#include <bits/stdc++.h>
using namespace std;
class compare {
 public:
  bool operator()(pair<int, int> x, pair<int, int> y) {
    if (x.second == y.second) {
      return x.first < y.first;
    }
    return x.second < y.second;
  }
};
int Set(int N, int pos) { return N = N | (1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<vector<int> > AdjLst;
  AdjLst.assign(n + 1, vector<int>());
  vector<int> dir(n + 1, -1);
  for (int i = 2; i <= n; i++) {
    int a;
    cin >> a;
    AdjLst[a].push_back(i);
    AdjLst[i].push_back(a);
  }
  queue<int> q;
  q.push(n);
  bool visited[n + 1];
  memset(visited, false, sizeof visited);
  visited[n] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < AdjLst[u].size(); i++) {
      if (!visited[AdjLst[u][i]]) {
        visited[AdjLst[u][i]] = true;
        dir[AdjLst[u][i]] = u;
        q.push(AdjLst[u][i]);
      }
    }
  }
  int start = 1;
  while (start != n) {
    cout << start << " ";
    start = dir[start];
  }
  cout << start << endl;
  return 0;
}
