#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
int a[N];
vector<int> G[N];
int cnt;
void dfs(int u, int pre) {
  a[++cnt] = u;
  for (auto v : G[u])
    if (v != pre) {
      dfs(v, u);
    }
}
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    int x;
    cin >> x;
    G[i].push_back(x);
  }
  dfs(n, n);
  for (int i = cnt; i >= 1; --i) cout << a[i] << ' ';
}
