#include <bits/stdc++.h>
using namespace std;
int n, type[100001], a[100001], lead[100001], cur[100001];
bool vs[100001];
void input() {
  scanf("%d", &n);
  for (int i = 1, _b = n; i <= _b; i++) scanf("%d", &type[i]);
  int x;
  memset(lead, 0, sizeof(lead));
  memset(a, 0, sizeof(a));
  for (int i = 1, _b = n; i <= _b; i++) {
    scanf("%d", &x);
    a[x] = i;
    lead[x]++;
  }
}
void dfs(int i) {
  vs[i] = true;
  if (type[i]) {
    cur[i] = 1;
    return;
  }
  if (lead[a[i]] != 1 && !type[a[i]]) return;
  if (!vs[a[i]]) dfs(a[i]);
  if (cur[a[i]]) cur[i] = cur[a[i]] + 1;
}
void process() {
  memset(vs, false, sizeof(vs));
  memset(cur, 0, sizeof(cur));
  for (int i = 0, _b = n; i <= _b; i++)
    if (lead[i] != 1 && !type[i]) vs[i] = true;
  for (int i = 1, _b = n; i <= _b; i++) {
    if (!vs[i]) dfs(i);
  }
  int ans = 0;
  int st = 0;
  for (int i = 1, _b = n; i <= _b; i++) {
    if (ans < cur[i]) {
      ans = cur[i];
      st = i;
    }
  }
  cout << ans << endl;
  while (!type[st]) {
    printf("%d ", st);
    st = a[st];
  }
  cout << st;
}
int main() {
  input();
  process();
  return 0;
}
