#include <bits/stdc++.h>
using namespace std;
int scan_d() {
  int ip = getchar(), ret = 0, flag = 1;
  for (; ip < '0' || ip > '9'; ip = getchar())
    if (ip == '-') {
      flag = -1;
      ip = getchar();
      break;
    }
  for (; ip >= '0' && ip <= '9'; ip = getchar()) ret = ret * 10 + ip - '0';
  return flag * ret;
}
long scan_ld() {
  int ip = getchar(), flag = 1;
  long ret = 0;
  for (; ip < '0' || ip > '9'; ip = getchar())
    if (ip == '-') {
      flag = -1;
      ip = getchar();
      break;
    }
  for (; ip >= '0' && ip <= '9'; ip = getchar()) ret = ret * 10 + ip - '0';
  return flag * ret;
}
long long scan_lld() {
  int ip = getchar(), flag = 1;
  long long ret = 0;
  for (; ip < '0' || ip > '9'; ip = getchar())
    if (ip == '-') {
      flag = -1;
      ip = getchar();
      break;
    }
  for (; ip >= '0' && ip <= '9'; ip = getchar()) ret = ret * 10 + ip - '0';
  return flag * ret;
}
long long unsigned scan_llu() {
  int ip = getchar();
  long long unsigned ret = 0;
  for (; ip < '0' || ip > '9'; ip = getchar())
    ;
  for (; ip >= '0' && ip <= '9'; ip = getchar()) ret = ret * 10 + ip - '0';
  return ret;
}
void print_d(int n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 10;
  char output_buffer[10];
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 10);
}
void print_ld(long n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 11;
  char output_buffer[11];
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 11);
}
void print_lld(long long n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 21;
  char output_buffer[21];
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 21);
}
void print_llu(long long unsigned n) {
  int i = 21;
  char output_buffer[21];
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 21);
}
void println_d(int n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 10;
  char output_buffer[11];
  output_buffer[10] = '\n';
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 11);
}
void println_ld(long n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 11;
  char output_buffer[12];
  output_buffer[11] = '\n';
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 12);
}
void println_lld(long long n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 21;
  char output_buffer[22];
  output_buffer[21] = '\n';
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 22);
}
void println_llu(long long unsigned n) {
  int i = 21;
  char output_buffer[22];
  output_buffer[21] = '\n';
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 22);
}
char sp;
void printsp_d(int n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 10;
  char output_buffer[11];
  output_buffer[10] = sp;
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 11);
}
void printsp_ld(long n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 11;
  char output_buffer[12];
  output_buffer[11] = sp;
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 12);
}
void printsp_lld(long long n) {
  if (n < 0) {
    n = -n;
    putchar('-');
  }
  int i = 21;
  char output_buffer[22];
  output_buffer[21] = sp;
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 22);
}
void printsp_llu(long long unsigned n) {
  int i = 21;
  char output_buffer[22];
  output_buffer[21] = sp;
  do {
    output_buffer[--i] = (n % 10) + '0';
    n /= 10;
  } while (n);
  do {
    putchar(output_buffer[i]);
  } while (++i < 22);
}
template <class T>
T mymax(T a, T b) {
  return a > b ? a : b;
}
template <class T>
T mymin(T a, T b) {
  return a < b ? a : b;
}
int main() {
  int s[100001], p[100001], nc[100001];
  int i;
  int n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    nc[i] = 0;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    nc[p[i]]++;
  }
  int imax = 0, pmax = -1, pl, ic, j;
  for (i = 1; i <= n; i++) {
    if (s[i]) {
      ic = j = i;
      pl = 0;
      while (p[j] != 0 && nc[p[j]] == 1) {
        pl++;
        j = p[j];
      }
      if (pl > pmax) {
        pmax = pl;
        imax = ic;
      }
    }
  }
  int path[100000] = {-1};
  i = imax;
  j = 0;
  while (p[i] != 0 && nc[p[i]] == 1) {
    path[j++] = i;
    i = p[i];
  }
  path[j] = i;
  printf("%d\n", pmax + 1);
  for (i = pmax; i >= 0; i--) {
    printf("%d ", path[i]);
  }
  return 0;
}
