#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int flag[100001];
int degree[100001];
int pre[100001];
int trace[100001];
int cnt;
int main() {
  int i, j;
  int n;
  while (scanf("%d", &n) != EOF) {
    vec.clear();
    memset(degree, 0, sizeof(degree));
    for (i = 1; i <= n; i++) {
      scanf("%d", &flag[i]);
      if (flag[i]) vec.push_back(i);
    }
    for (i = 1; i <= n; i++) {
      scanf("%d", &pre[i]);
      if (pre[i]) degree[pre[i]]++;
    }
    cnt = 0;
    for (i = 0; i < vec.size(); i++) {
      int now = vec[i];
      j = pre[now];
      int tcnt = 1;
      while (j && flag[j] == 0 && degree[j] < 2) {
        j = pre[j];
        tcnt++;
      }
      if (tcnt > cnt) {
        cnt = 0;
        j = now;
        while (cnt < tcnt) {
          trace[cnt++] = j;
          j = pre[j];
        }
      }
    }
    printf("%d\n", cnt);
    printf("%d", trace[cnt - 1]);
    for (i = cnt - 2; i >= 0; i--) printf(" %d", trace[i]);
    printf("\n");
  }
  return 0;
}
