#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 7;
vector<int> g[M], res;
void dfs(int node, int par) {
  for (auto x : g[node]) {
    if (x != par) {
      dfs(x, node);
      cout << x << ' ';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    g[i].push_back(x);
  }
  dfs(n, -1);
  cout << n << endl;
  return 0;
}
