#include <bits/stdc++.h>
using namespace std;
int t[100001];
int nb[100001] = {0};
void reponse(int i) {
  if (nb[t[i]] == 1) reponse(t[i]);
  cout << i << " ";
}
int main() {
  int n, m = 0, s;
  bool o[100001];
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> o[i];
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    nb[t[i]]++;
  }
  nb[0] = 2;
  for (int i = 1; i <= n; i++)
    if (o[i]) {
      int l = 1, v = i;
      while (nb[t[v]] == 1) {
        v = t[v];
        l++;
      }
      if (l > m) {
        m = l;
        s = i;
      }
    }
  cout << m << endl;
  reponse(s);
  return 0;
}
