#include <bits/stdc++.h>
int a[100001], b[100001], c[100002], d[100001], ans = 0, maxans, n, i, j, k = 1;
void fun(int x) {
  ans++;
  if (c[b[x]] == 1 && b[x] > 0) fun(b[x]);
}
void morefun(int y) {
  d[k] = y;
  k++;
  if (c[b[y]] == 1 && b[y] > 0) morefun(b[y]);
}
int main() {
  scanf("%d", &n);
  c[0] == 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    c[i] = 0;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    c[b[i]]++;
  }
  for (i = 1; i <= n; i++)
    if (a[i] == 1) {
      fun(i);
      if (ans > maxans) {
        maxans = ans;
        j = i;
      }
      ans = 0;
    }
  printf("%d\n", maxans);
  morefun(j);
  for (i = maxans; i > 0; i--) printf("%d ", d[i]);
}
