#include <bits/stdc++.h>
using namespace std;
int G[200005];
int T;
stack<int> road;
int main() {
  while (scanf("%d", &T) != EOF) {
    int i;
    for (i = 2; i <= T; i++) {
      scanf("%d", &G[i]);
    }
    road.push(T);
    int q = T;
    while (q != 1) {
      q = G[q];
      road.push(q);
    }
    while (!road.empty()) {
      printf("%d ", road.top());
      road.pop();
    }
    return 0;
  }
}
