#include <bits/stdc++.h>
typedef struct _ {
  int id;
  struct _* next;
} Node;
Node** list;
int n, a, ans[200005];
void find(int start, int pre) {
  for (Node* it = list[start]; it; it = it->next) {
    if (start == n) {
      for (int i = 1; i < n; i++)
        if (ans[i]) printf(" %d", i);
      return;
    }
    if (it->id == pre) continue;
    ans[it->id] = 1;
    find(it->id, start);
    ans[it->id] = 0;
  }
}
int main() {
  scanf("%d", &n);
  list = (Node**)malloc(sizeof(Node*) * (n + 1));
  for (int i = 1; i <= n; i++) list[i] = NULL;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &a);
    Node* tmp = list[a];
    list[a] = (Node*)malloc(sizeof(Node));
    list[a]->id = i;
    list[a]->next = tmp;
    tmp = list[i];
    list[i] = (Node*)malloc(sizeof(Node));
    list[i]->id = a;
    list[i]->next = tmp;
  }
  printf("1");
  find(1, n);
  printf(" %d", n);
  for (int i = 1; i <= n; i++) {
    while (list[i]) {
      Node* del = list[i];
      list[i] = list[i]->next;
      free(del);
    }
  }
  free(list);
  return 0;
}
