#include <bits/stdc++.h>
using namespace std;
int n;
void addedge(vector<int> adj[], int a, int b) {
  adj[a].push_back(b);
  adj[b].push_back(a);
}
deque<int> st;
void printst() {
  for (auto it = st.begin(); it != st.end(); ++it) {
    cout << *it << " ";
  }
  cout << "\n";
}
void dfs(vector<int> adj[], int a, vector<bool> &visited) {
  visited[a] = true;
  st.push_back(a);
  for (int i = 0; i < (int)adj[a].size(); ++i) {
    if (!visited[adj[a][i]]) {
      if (adj[a][i] == n) {
        st.push_back(n);
        printst();
      }
      dfs(adj, adj[a][i], visited);
    }
  }
  st.pop_back();
}
int main() {
  cin >> n;
  vector<int> adj[n + 1];
  for (int i = 2; i < n + 1; ++i) {
    int temp;
    cin >> temp;
    addedge(adj, temp, i);
  }
  vector<bool> visited(n + 1, false);
  dfs(adj, 1, visited);
}
