#include <bits/stdc++.h>
using namespace std;
int hotel[100005];
int prior[100005] = {0};
int cnt_way[100005] = {0};
void print(int x) {
  if (x == 0) return;
  if (cnt_way[x] != 1) return;
  print(prior[x]);
  printf("%d ", x);
}
int main() {
  int n, x;
  int h = 0;
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &x);
    if (x == 1) hotel[h++] = i;
  }
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &x);
    cnt_way[x]++;
    if (x > 0) {
      if (prior[i] == 0)
        prior[i] = x;
      else
        prior[i] = 0;
    }
  }
  int ans, cnt_ans = 0;
  for (int i = 0; i < h; i++) {
    x = hotel[i];
    int cnt = 1;
    x = prior[x];
    while (x != 0) {
      if (cnt_way[x] != 1) break;
      x = prior[x];
      cnt++;
    }
    if (cnt_ans < cnt) {
      ans = hotel[i];
      cnt_ans = cnt;
    }
  }
  printf("%d\n", cnt_ans);
  print(prior[ans]);
  printf("%d\n", ans);
}
