#include <bits/stdc++.h>
using namespace std;
struct obj {
  bool type;
  vector<int> outs;
  int in;
};
bool comp(vector<int> a, vector<int> b) {
  if (a.size() > b.size()) return true;
  return false;
}
int main() {
  int n;
  obj *a;
  vector<int> hotels;
  vector<vector<int>> results;
  cin >> n;
  a = new obj[n];
  for (int i = 0; i < n; i++) {
    bool type;
    cin >> type;
    a[i].type = type;
    if (type) hotels.push_back(i);
  }
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    a[i].in = temp - 1;
    if (temp) a[temp - 1].outs.push_back(i);
  }
  for (vector<int>::iterator it = hotels.begin(); it != hotels.end(); it++) {
    int thisObj = *it, size = a[thisObj].outs.size();
    vector<int> way;
    do {
      way.push_back(thisObj + 1);
      if (size > 1) break;
      thisObj = a[thisObj].in;
      if (thisObj < 0) break;
      size = a[thisObj].outs.size();
    } while (size == 1);
    results.push_back(way);
  }
  sort(results.begin(), results.end(), comp);
  vector<int> result = *results.begin();
  cout << result.size() << endl;
  for (vector<int>::reverse_iterator it = result.rbegin(); it != result.rend();
       it++)
    cout << *it << ' ';
  return 0;
}
