#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> types(n);
  vector<int> parents(n);
  vector<int> deg(n, 0);
  for (int i = 0; i < n; i++) cin >> types[i];
  for (int i = 0; i < n; i++) {
    cin >> parents[i];
    parents[i]--;
    if (parents[i] != -1) {
      deg[parents[i]]++;
    }
  }
  int best = 0;
  int bestInd = 0;
  for (int i = 0; i < n; i++) {
    if (types[i] == 1) {
      int len = 1;
      int cur = i;
      while (parents[cur] != -1 && deg[parents[cur]] == 1 &&
             types[parents[cur]] == 0) {
        len++;
        cur = parents[cur];
      }
      if (len > best) {
        bestInd = i;
        best = len;
      }
    }
  }
  vector<int> bestPath(best);
  bestPath[best - 1] = bestInd;
  for (int i = best - 2; i >= 0; i--) {
    bestPath[i] = parents[bestPath[i + 1]];
  }
  cout << best << endl;
  for (int i = 0; i < best; i++) cout << (bestPath[i] + 1) << " ";
  cout << endl;
  return 0;
}
