#include <bits/stdc++.h>
using namespace std;
int n, tag[100001], ok[100001], pre[100001];
vector<vector<int>> graph, rgraph;
queue<int> q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(pre, -1, sizeof pre);
  cin >> n;
  graph.resize(n + 1);
  rgraph.resize(n + 1);
  for (int i = 1; i <= n; i += 1) {
    cin >> tag[i];
    if (tag[i]) {
      q.push({i});
    }
  }
  for (int i = 1; i <= n; i += 1) {
    int a;
    cin >> a;
    graph[a].push_back(i);
    rgraph[i].push_back(a);
  }
  for (int i = 1; i <= n; i += 1) {
    if (graph[i].size() == 1) {
      ok[i] = true;
    }
  }
  int ans, dist = 0;
  while (q.size()) {
    dist += 1;
    int f = q.size();
    while (f--) {
      int next = q.front();
      ans = next;
      q.pop();
      ans = next;
      for (int i : rgraph[next]) {
        if (ok[i]) {
          q.push(i);
          pre[i] = next;
        }
      }
    }
  }
  cout << dist << endl;
  vector<int> v;
  while (ans != -1) {
    v.push_back(ans);
    ans = pre[ans];
  }
  for (int i : v) {
    cout << i << " ";
  }
  cout << endl;
}
