#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, mod = 1e9 + 7, inf = 1e18 + 7;
vector<long long> adj[N];
long long n;
vector<long long> path;
bool ck[N];
void dfs(long long u) {
  path.push_back(u);
  if (u == n) {
    for (long long i = 0; i < path.size(); i++) {
      cout << path[i] << ' ';
    }
    exit(0);
  }
  ck[u] = 1;
  for (long long i = 0; i < adj[u].size(); i++) {
    if (!ck[adj[u][i]]) {
      dfs(adj[u][i]);
    }
  }
  path.pop_back();
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 2; i < n + 1; i++) {
    long long x;
    cin >> x;
    adj[x].push_back(i);
    adj[i].push_back(x);
  }
  dfs(1);
}
