#include <bits/stdc++.h>
using namespace std;
const int NMax = 100000;
int N, A[NMax], T[NMax], C[NMax];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", T + i);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    A[i]--;
  }
  for (int i = 0; i < N; i++) C[i] = 0;
  for (int i = 0; i < N; i++)
    if (A[i] != -1) C[A[i]]++;
  int ret = 0, reti = -1;
  for (int i = 0; i < N; i++)
    if (T[i] == 1) {
      int c = 1;
      int j = i;
      while (A[j] != -1 && C[A[j]] == 1) {
        j = A[j];
        c++;
      }
      if (c > ret) {
        ret = c;
        reti = i;
      }
    }
  printf("%d\n", ret);
  vector<int> output;
  for (int i = 0; i < ret; i++) {
    output.push_back(reti);
    reti = A[reti];
  }
  for (int i = 0; i < ret; i++) {
    if (i) printf(" ");
    printf("%d", output[ret - 1 - i] + 1);
  }
  puts("");
  return 0;
}
