#include <bits/stdc++.h>
using namespace std;
typedef struct tag {
  int status;
  int parent;
  int degree = 0;
} node;
node travel[100005];
int use[100005];
bool compare(node a, node b) { return (a.status > b.status); }
vector<int> tmp, path;
vector<int>::iterator it;
void dfs(int ind) {
  if (travel[ind].degree >= 2 || ind == 0) return;
  tmp.push_back(ind);
  dfs(travel[ind].parent);
}
int main() {
  int n, max = INT_MIN, temp, k = 0;
  scanf("%d", &n);
  for (int j = 1; j <= n; j++) {
    scanf("%d", &travel[j].status);
    if (travel[j].status) {
      use[k++] = j;
    }
  }
  for (int j = 1; j <= n; j++) {
    scanf("%d", &travel[j].parent);
    travel[travel[j].parent].degree++;
  }
  for (int i = 0; i < k; i++) {
    dfs(use[i]);
    if (tmp.size() > path.size()) {
      path.clear();
      it = path.begin();
      path.insert(it, tmp.rbegin(), tmp.rend());
    }
    tmp.clear();
  }
  printf("%d\n", path.size());
  for (it = path.begin(); it != path.end(); it++) printf("%d ", *it);
  return (0);
}
