#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 2e5 + 5;
int p[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    p[i] = x;
  }
  vector<int> path;
  int x = n;
  while (1) {
    path.push_back(x);
    x = p[x];
    if (x == 0) break;
  }
  reverse(begin(path), end(path));
  for (int x : path) cout << x << ' ';
}
