#include <bits/stdc++.h>
using namespace std;
const int n_max = 100001;
int p[n_max], out_deg[n_max], type[n_max];
vector<int> ans_path, temp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> type[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    p[i]--;
    if (p[i] >= 0) {
      out_deg[p[i]]++;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (!type[i]) continue;
    int j = i;
    temp.clear();
    temp.push_back(j);
    while (out_deg[p[j]] <= 1 && p[j] != -1) {
      j = p[j];
      temp.push_back(j);
    }
    if (temp.size() > ans_path.size()) {
      reverse(temp.begin(), temp.end());
      ans_path = temp;
    }
  }
  cout << ans_path.size() << '\n';
  for (int i : ans_path) {
    cout << i + 1 << ' ';
  }
}
