#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int INF = 0x3f3f3f3f;
int type[maxn], parent[maxn], son_num[maxn];
vector<int> s1, s2;
int main() {
  int i, j, n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &type[i]);
  memset(parent, -1, sizeof(parent));
  for (i = 1; i <= n; i++) {
    scanf("%d", &j);
    if (j) {
      parent[i] = j;
      son_num[j]++;
    }
  }
  int len, tlen;
  for (i = 1; i <= n; i++) {
    if (type[i] == 1) {
      s2.clear();
      j = i;
      while (j != -1 && son_num[j] < 2) {
        s2.push_back(j);
        j = parent[j];
      }
    }
    if (s2.size() > s1.size()) s1 = s2;
  }
  printf("%d\n", s1.size());
  for (i = s1.size() - 1; i > 0; i--) printf("%d ", s1[i]);
  printf("%d\n", s1[i]);
  return 0;
}
