#include <bits/stdc++.h>
using namespace std;
set<int> ans;
void DFS(int Node, vector<vector<int>>& graph, vector<bool>& visted) {
  ans.insert(Node);
  visted[Node] = 1;
  int length;
  for (auto child : graph[Node]) {
    if (!visted[child]) {
      if (child == 1) {
        cout << 1;
        for (auto i : ans) cout << " " << i;
        return;
      }
      DFS(child, graph, visted);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int num, number, Node = 2, t;
  cin >> num;
  t = num - 1;
  vector<vector<int>> graph(num + 1);
  while (t--) {
    cin >> number;
    graph[number].push_back(Node);
    graph[Node].push_back(number);
    Node++;
  }
  graph[num].push_back(number);
  vector<bool> visted(num + 1);
  DFS(num, graph, visted);
}
