#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m, par[maxn];
vector<int> edges[maxn];
bool vis[maxn], f;
vector<int> path;
void dfs(int u, int p) {
  vis[u] = 1;
  par[u] = p;
  for (auto v : edges[u]) {
    if (!vis[v]) dfs(v, u);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    edges[i + 1].push_back(x);
    edges[x].push_back(i + 1);
  }
  dfs(1, -1);
  int p = n;
  while (p != -1) {
    path.push_back(p);
    p = par[p];
  }
  reverse(path.begin(), path.end());
  for (auto x : path) cout << x << ' ';
  cout << endl;
  return 0;
}
