#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
typedef pair<int, int>PII;
const int INF = 0x3f3f3f3f;
vector<int>a[N];
int dist[N];
int maxx = -INF;
void bfs()
{
dist[100001] = 0;
queue<int>q;
q.push(100001);
while (q.size())
{
auto t = q.front();
q.pop();
for (auto p : a[t])
{
q.push(p);
dist[p] = dist[t] + 1;
maxx = max(maxx, dist[p]);//更新最小辈分
}
}
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (x == -1)//因为没有下标-1,所以放到100001
{
a[100001].push_back(i);
}
else
a[x].push_back(i);
}
bfs();
int flag = 1;
cout << maxx<<endl;
for (int i = 1; i <= n; i++)//找到最小辈分的后代
{
if (dist[i] == maxx && flag)cout << i, flag = 0;
else if (dist[i] == maxx)cout << " " << i;
}
return 0;
}