#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], num[100005], c[100005], pre[100005];
int main() {
  int n, t, j, k, g, maxn;
  while (scanf("%d", &n) != EOF) {
    memset(num, 0, sizeof(num));
    for (t = 1; t <= n; ++t) scanf("%d", a + t);
    for (t = 1; t <= n; ++t) {
      scanf("%d", pre + t);
      num[pre[t]]++;
    }
    for (t = 1, maxn = 0; t <= n; ++t) {
      if (a[t]) {
        for (j = t, k = 1; j == t || (num[j] == 1 && !a[j]); j = pre[j]) {
          if (j == 0) break;
          b[k++] = j;
        }
        k--;
        if (k > maxn) {
          maxn = k;
          for (j = 1; j <= k; ++j) c[j] = b[j];
        }
      }
    }
    printf("%d\n", maxn);
    for (t = maxn; t > 1; --t) printf("%d ", c[t]);
    printf("%d\n", c[t]);
  }
  return 0;
}
