#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 * 1000 + 1;
bool obj[MAX_N];
vector<int> graph[MAX_N];
int N;
int dad[MAX_N];
int dp[MAX_N];
bool mark[MAX_N];
queue<int> BB;
int dad2[MAX_N];
int dad3[MAX_N];
void input() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> obj[i];
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a) {
      graph[a - 1].push_back(i);
      dad[i] = a - 1;
    } else
      dad[i] = -1;
  }
}
int run() {
  for (int i = 0; i < N; i++) {
    if (graph[i].size() <= 1) mark[i] = true;
  }
  for (int i = 0; i < N; i++) {
    if (obj[i]) BB.push(i);
    dad2[i] = -1;
    dad3[i] = 0;
  }
  while (BB.size()) {
    int y = BB.front();
    if (mark[dad[y]] && dad[y] != -1) {
      dad2[dad[y]] = y;
      dad3[dad[y]] = dad3[y] + 1;
      BB.push(dad[y]);
    }
    BB.pop();
  }
  int y = 0;
  for (int i = 1; i < N; i++) {
    if (dad3[y] < dad3[i]) y = i;
  }
  if (y == 0 && dad3[y] == 0) {
    for (int i = 0; i < N; i++)
      if (obj[i]) {
        y = i;
        break;
      }
  }
  return y;
}
void output(int ans) {
  cout << dad3[ans] + 1 << endl;
  int y = ans;
  while (y != -1) {
    cout << y + 1 << " ";
    y = dad2[y];
  }
  cout << endl;
}
int main() {
  input();
  output(run());
}
