#include <bits/stdc++.h>
using namespace std;
vector<int> A, c;
int C[100005], a[100005], b[100005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (b[i]) C[b[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      c.clear();
      int j = i;
      c.push_back(i);
      while (b[j] && a[b[j]] == 0 && C[b[j]] == 1) {
        c.push_back(b[j]);
        j = b[j];
      }
      if (c.size() > A.size()) A = c;
    }
  }
  reverse(A.begin(), A.end());
  cout << A.size() << endl;
  for (int i = 0; i < A.size(); i++) cout << A[i] << " ";
  return 0;
}
