#include <bits/stdc++.h>
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
const int mod = 1000000007;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  bool first = true;
  os << "[";
  for (auto i : v) {
    if (!first) os << ", ";
    os << i;
    first = false;
  }
  return os << "]";
}
const int N = 2 * 1e5 + 10;
int n, p[N], x;
bool mark[N];
std::vector<int> v[N];
void dfs(int s, int p) {
  if (s == n) {
    mark[s] = 1;
    return;
  }
  for (auto i : v[s]) {
    if (i != p) {
      dfs(i, s);
      if (mark[i]) mark[s] = 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    cin >> x;
    v[i].push_back(x);
    v[x].push_back(i);
  }
  dfs(1, -1);
  for (int i = 1; i <= n; ++i) {
    if (mark[i]) cout << i << ' ';
  }
  return 0;
}
