#include <bits/stdc++.h>
using namespace std;
bool b[100005];
int p[100005];
int gt[100005], st[100005];
vector<int> res;
int f(int w) {
  if (gt[w] == 0) {
    if (p[w] == 0 || b[p[w] - 1] || st[p[w] - 1] > 1)
      gt[w] = 1;
    else
      gt[w] = 1 + f(p[w] - 1);
  }
  return gt[w];
}
void ff(int w) {
  res.push_back(w);
  if (p[w] == 0 || b[p[w] - 1] || st[p[w] - 1] > 1) return;
  ff(p[w] - 1);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0, a; i < n; ++i) {
    cin >> a;
    b[i] = a;
  }
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    ++st[p[i] - 1];
  }
  int M = 0, fn = 0;
  for (int i = 0; i < n; ++i)
    if (b[i]) {
      int t = f(i);
      if (t > M) {
        M = t;
        fn = i;
      }
    }
  cout << M << endl;
  ff(fn);
  for (int i = res.size() - 1; i >= 0; --i) cout << res[i] + 1 << ' ';
  return 0;
}
