#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  long n, tmp, te;
  cin >> n;
  bool type[n + 1];
  long ski[n + 1], path[n + 1];
  for (long i = 1; i <= n; i++) {
    cin >> type[i];
  }
  for (long i = 1; i <= n; i++) {
    ski[i] = 0;
  }
  for (long i = 1; i <= n; i++) {
    cin >> tmp;
    ski[tmp]++;
    path[i] = tmp;
  }
  long m = 0, tm = 0;
  vector<long> ans, temp;
  for (long i = 1; i <= n; i++) {
    tm = 1;
    temp.clear();
    if (type[i]) {
      temp.push_back(i);
      te = i;
      while (1) {
        tmp = path[te];
        if (ski[tmp] != 1) break;
        if (tmp == path[tmp]) break;
        temp.push_back(tmp);
        tm++;
        te = tmp;
      }
      if (tm > m) {
        m = tm;
        ans.clear();
        for (vector<long>::iterator it = temp.begin(); it != temp.end(); it++)
          ans.push_back(*it);
      }
    }
  }
  cout << m << endl;
  reverse(ans.begin(), ans.end());
  for (vector<long>::iterator it = ans.begin(); it != ans.end(); it++)
    cout << *it << ' ';
}
