#include <bits/stdc++.h>
using namespace std;
int maxn;
int vis[100010], a[100010], in[100010], temp[100010], res[100010];
vector<int> q[100010];
int bfs(int x) {
  int i, sum = 1, hash[100010] = {0};
  hash[x] = 1;
  while (in[x] < 2) {
    temp[sum++] = x;
    if (!hash[q[x][0]]) {
      if (q[x][0] == 0) break;
      x = q[x][0];
    }
  }
  return sum - 1;
}
int main() {
  int i, n;
  while (scanf("%d", &n) != EOF) {
    maxn = 0;
    memset(in, 0, sizeof(in));
    for (i = 1; i <= n; i++) scanf("%d", &vis[i]);
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      in[a[i]]++;
      q[i].push_back(a[i]);
    }
    for (i = 1; i <= n; i++) {
      if (vis[i]) {
        int t = bfs(i);
        if (t > maxn) {
          maxn = t;
          for (int j = 1; j <= maxn; j++) res[j] = temp[j];
        }
      }
    }
    printf("%d\n", maxn);
    for (i = maxn; i > 0; i--) {
      if (i != maxn) printf(" ");
      printf("%d", res[i]);
    }
    printf("\n");
  }
  return 0;
}
