#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int type[n + 1], a[n + 1];
  memset(a, -1, (n + 1) * sizeof(int));
  for (int i = 1; i <= n; i++) cin >> type[i];
  int num;
  for (int i = 1; i <= n; i++) {
    cin >> num;
    if (a[num] == -1)
      a[num] = i;
    else
      a[num] = 0;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] == -1) a[i] = 0;
  int b[n + 1];
  memset(b, 0, (n + 1) * sizeof(int));
  for (int i = 1; i <= n; i++) b[a[i]] = i;
  b[0] = 0;
  int max = -1, kmax = -1;
  for (int i = 1; i <= n; i++)
    if (type[i] == 1) {
      int k = i;
      int c = 0;
      while (k) {
        k = b[k];
        c++;
      }
      if (c > max) {
        max = c;
        kmax = i;
      }
    }
  int k = kmax, i = 1;
  int c[n + 1];
  while (k) {
    c[i++] = k;
    k = b[k];
  }
  cout << max << endl;
  for (int i = max; i >= 1; i--) {
    cout << c[i];
    if (i == 1)
      cout << endl;
    else
      cout << ' ';
  }
  return 0;
}
