#include <bits/stdc++.h>
using namespace std;
int A[100005], t[100005], i, n, ANS[100005], ans, du[100005], B[100005], now, o,
    MAX, j;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    if (A[i] == 1) t[++o] = i;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &B[i]);
    du[B[i]]++;
  }
  for (i = 1; i <= o; i++) {
    ans = 1;
    now = t[i];
    while (B[now] != 0 && A[B[now]] == 0 && du[B[now]] == 1) {
      now = B[now];
      ans++;
    }
    if (ans > MAX) MAX = ans;
  }
  cout << MAX << endl;
  for (i = 1; i <= o; i++) {
    ans = 1;
    now = t[i];
    while (B[now] != 0 && A[B[now]] == 0 && du[B[now]] == 1) {
      ANS[MAX - ans + 1] = now;
      now = B[now];
      ans++;
    }
    ANS[1] = now;
    if (ans == MAX) {
      for (j = 1; j <= MAX; j++) cout << ANS[j] << ' ';
      return 0;
    }
  }
}
