#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> grafo[100050];
vector<int> grafoT[100050];
vector<int> casa;
void bfs() {
  queue<pair<int, int> > q;
  int pai[n + 1];
  for (auto x : casa) {
    pai[x] = x;
    q.push(pair<int, int>(x, 0));
  }
  int alcancei;
  int maior = -1;
  while (!q.empty()) {
    pair<int, int> aux = q.front();
    q.pop();
    int u = aux.first;
    int w = aux.second;
    if (w > maior) {
      maior = w;
      alcancei = u;
    }
    for (auto v : grafoT[u]) {
      if (grafo[v].size() > 1) continue;
      pai[v] = u;
      q.push(pair<int, int>(v, w + 1));
    }
  }
  printf("%d\n", maior + 1);
  while (pai[alcancei] != alcancei) {
    printf("%d ", alcancei);
    alcancei = pai[alcancei];
  }
  printf("%d\n", alcancei);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int val;
    scanf("%d", &val);
    if (val == 1) {
      casa.push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    int val;
    scanf("%d", &val);
    if (val == 0) continue;
    grafo[val].push_back(i);
    grafoT[i].push_back(val);
  }
  bfs();
  return 0;
}
