#include <bits/stdc++.h>
using namespace std;
bool tipas[100000];
vector<int> edgeout[100000];
vector<int> edgein[100000];
int cur = 0;
int best = 0, beststart = -1;
void dfs(int v) {
  cur++;
  if (edgein[v].size() != 0 && edgeout[edgein[v][0]].size() == 1)
    dfs(edgein[v][0]);
}
void dfs2(int v) {
  if (edgein[v].size() != 0 && edgeout[edgein[v][0]].size() == 1)
    dfs2(edgein[v][0]);
  cout << v + 1 << ' ';
}
int main(void) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> tipas[i];
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a != 0) {
      a--;
      edgeout[a].push_back(i);
      edgein[i].push_back(a);
    }
  }
  for (int i = 0; i < n; i++) {
    if (tipas[i]) {
      cur = 0;
      dfs(i);
      if (cur > best) {
        best = cur;
        beststart = i;
      }
    }
  }
  cout << best << endl;
  dfs2(beststart);
}
