#include <bits/stdc++.h>
using namespace std;
int n;
int parent[100005];
int is_hotel[100005];
int valid[100005];
vector<int> solve(int i) {
  vector<int> v;
  while (1) {
    v.push_back(i);
    if (parent[i] < 0) break;
    if (valid[parent[i]] < 1) break;
    i = parent[i];
  }
  return v;
}
int main() {
  while (cin >> n) {
    for (int i = (0); i < (n); ++i) {
      cin >> is_hotel[i];
      valid[i] = 2;
    }
    for (int i = (0); i < (n); ++i) {
      cin >> parent[i];
      parent[i]--;
      if (parent[i] >= 0) valid[parent[i]]--;
    }
    int best = 0;
    vector<int> vbest;
    for (int i = (0); i < (n); ++i) {
      if (is_hotel[i]) {
        vector<int> v = solve(i);
        if (v.size() > best) {
          best = v.size();
          vbest = v;
        }
      }
    }
    printf("%d\n", best);
    for (int i = best - 1; i >= 0; i -= 1) {
      printf("%d ", vbest[i] + 1);
    }
    printf("\n");
  }
  return 0;
}
