#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int d[100001] = {};
  int t[100001];
  int e[100001];
  int p[100001];
  int n, ans = 0, st;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &e[i]);
    d[e[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (t[i] == 0) continue;
    int tmp = 1, c = i, idx = 1;
    int tmp_p[100001];
    memset(tmp_p, -1, sizeof(tmp_p));
    while (1) {
      tmp_p[idx] = c;
      idx++;
      if (d[c] > 1 || (t[c] == 1 && c != i)) {
        tmp--;
        tmp_p[idx - 1] = -1;
        break;
      }
      if (!e[c]) break;
      c = e[c];
      tmp++;
    }
    if (tmp > ans) {
      st = i;
      ans = tmp;
      memcpy(p, tmp_p, sizeof(int) * 100001);
    }
  }
  printf("%d\n", ans);
  if (!ans) return 0;
  printf("%d", p[ans]);
  for (int i = ans - 1; i > 0; i--) printf(" %d", p[i]);
}
