#include <bits/stdc++.h>
using namespace std;
const int nmax = int(1e5) + 1;
int n;
bool a[nmax];
int dg[nmax];
int h[nmax];
int t[nmax];
void build(int v) {
  if (!v || dg[v] > 1) return;
  build(t[v]);
  cout << v << " ";
}
int main() {
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    cin >> a[i + 1];
  }
  int val;
  for (int i = 0; i < (int)n; i++) {
    cin >> t[i + 1];
    dg[t[i + 1]]++;
  }
  int sv = 0, dmax = 0;
  for (int i = 0; i < (int)n; i++) {
    if (a[i + 1] == true) {
      int v = i + 1;
      int dim = 1;
      while (t[v] != 0 && dg[t[v]] < 2) {
        v = t[v];
        dim++;
      }
      if (dim > dmax) {
        dmax = dim;
        sv = i + 1;
      }
    }
  }
  cout << dmax << "\n";
  build(sv);
  return 0;
}
