#include <bits/stdc++.h>
const double PI = acos(-1.);
const long long inf = 10000000000000LL;
const int MAXN = 100000 + 13;
using namespace std;
int a[MAXN], n;
int b[MAXN];
int k[MAXN];
int len(int start) {
  int r = 0, i = start;
  do {
    ++r;
    i = a[i];
  } while (i && k[i] == 1);
  return r;
}
void out(int p) {
  if (a[p] && k[a[p]] == 1) out(a[p]);
  cout << p << ' ';
}
int main() {
  int mp = -1, p = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    if (b[i]) p = i;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ++k[a[i]];
  }
  for (int i = 1; i <= n; ++i) {
    if (!b[i]) continue;
    int tmp = len(i);
    if (tmp >= mp) {
      mp = tmp;
      p = i;
    }
  }
  cout << mp << endl;
  out(p);
  cout << endl;
  return 0;
}
