#include <bits/stdc++.h>
using namespace std;
void findpath(int index, int *a, int *b, int *noofb, int *temppath,
              int *templen);
int main() {
  int n;
  scanf("%d", &n);
  int a[n], b[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int noofb[n];
  for (int i = 0; i < n; ++i) {
    noofb[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
    b[i]--;
    if (b[i] == -1)
      ;
    else {
      noofb[b[i]]++;
    }
  }
  vector<int> path;
  int len = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == 1) {
      int temppath[100000];
      int templen = 0;
      findpath(i, a, b, noofb, temppath, &templen);
      if (templen > len) {
        path.clear();
        len = templen;
        for (int i = 0; i < templen; ++i) {
          path.push_back(temppath[i]);
        }
      }
    }
  }
  printf("%d\n", len);
  int flag = 0;
  for (int i = len - 1; i >= 0; i--) {
    if (flag == 0) {
      printf("%d", path[i] + 1);
      flag = 1;
    } else {
      printf(" %d", path[i] + 1);
    }
  }
  printf("\n");
  return 0;
}
void findpath(int index, int *a, int *b, int *noofb, int *temppath,
              int *templen) {
  while (1) {
    if (index == -1) {
      break;
    }
    temppath[*templen] = index;
    *templen = *templen + 1;
    if (noofb[b[index]] == 1 && index >= 0) {
    } else {
      break;
    }
    index = b[index];
  }
  return;
}
