#include <bits/stdc++.h>
using namespace std;
vector<long long int> edges[200005];
bool vis[200005];
long long int parent[200005];
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 2; i <= n; i++) {
    long long int p;
    cin >> p;
    edges[p].push_back(i);
    edges[i].push_back(p);
  }
  queue<long long int> q;
  long long int src = 1;
  parent[src] = -1;
  vis[src] = 1;
  q.push(src);
  while (!q.empty()) {
    long long int u = q.front();
    q.pop();
    for (auto x : edges[u]) {
      if (!vis[x]) {
        vis[x] = 1;
        parent[x] = u;
        q.push(x);
        if (x == n) {
          break;
        }
      }
    }
  }
  vector<long long int> path;
  long long int crawl = n;
  path.push_back(crawl);
  while (parent[crawl] != -1) {
    path.push_back(parent[crawl]);
    crawl = parent[crawl];
  }
  reverse(path.begin(), path.end());
  for (auto x : path) {
    cout << x << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
