#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
int n;
bool vis[200005];
vector<int> ans;
void dfs(int v) {
  vis[v] = true;
  ans.push_back(v);
  if (v == n - 1)
    for (int j = 0; j < ans.size(); j += 1) cout << ans[j] + 1 << " ";
  for (int i = 0; i < adj[v].size(); i += 1) {
    if (!vis[adj[v][i]]) dfs(adj[v][i]);
  }
  ans.pop_back();
}
int main() {
  cin >> n;
  int x;
  adj.resize(n);
  for (int i = 1; i < n; i += 1) {
    cin >> x;
    x--;
    adj[x].push_back(i);
  }
  dfs(0);
}
